Typesafe config does not substitude environment variables [solved]

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

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]

I have a similar problem. I want to provide the host part of the slick db url from an environment variable:


When I run the application, this just will not resolve the environment variable X_POSTGRES_HOST.

Slick expects a String in slick.dbs.default.db.url, but if I provide a String with quotes like shown above, the environment variable will not be resolved. I’m stuck. Any ideas?

Got this information here that solves it for me: https://github.com/lightbend/config/issues/633

Substitution only happens outside quotes. This is a JSON superset, so quoted strings have the same meaning as in JSON. write it as ”text“${HOST}”moretext”