Typesafe config does not substitude environment variables [solved]

configuration

(Aki) #1

I’m deploying a playframework app within kubernetes and want to configure some key’s based on environment variables that I set in the kubernetes deployment yaml file.


So the environment variables CASSANDRA_SERVICE_NAME and CASSANDRA_NAMESPACE are assigned to some values and I want to reference them from my application.conf:

cassandra-journal.contact-points = ["${CASSANDRA_SERVICE_NAME}.${CASSANDRA_NAMESPACE}.svc.cluster.local"]

The typesafe config documentation claims that unset variables get substituded agains environent variables, but that does not work in my case:

All following lines yield ["${CASSANDRA_SERVICE_NAME}.${CASSANDRA_NAMESPACE}.svc.cluster.local"]

// `config: play.api.Configuration` is injected into my play app
println(config.get[Seq[String]]("cassandra-journal.contact-points"))
println(config.underlying.getStringList("cassandra-journal.contact-points"))
println(config.underlying.resolve().getStringList("cassandra-journal.contact-points"))

The environment variable is definitely set:

System.getenv("CASSANDRA_SERVICE_NAME") yields the correct value.
ConfigFactory.systemEnvironment does also contain my environment variables


(Aki) #2

I just found the solution: Unlike scala, the ${...} syntax in hocon may not used within string literals.
The following worked:

contact-points = [${CASSANDRA_SERVICE_NAME}.${CASSANDRA_NAMESPACE}.svc.cluster.local]