Typesafe config does not substitude environment variables [solved]


(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

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]