Substituting environment variables into HOCON config


#1

Hi,

How would I pass environment variables so that they’re substituted into the typesafe/hocon config files?

For example, I’m trying to do
collectorPort=8080 ./snowplow-stream-collector-0.7.0 --config ~/downloads/collector.conf

So that I can change the port for dev, test and prod environments.

Thanks,


#2

The error raised is
Exception in thread "main" com.typesafe.config.ConfigException$NotResolved: port has not been resolved, you need to call Config#resolve(), see API docs for Config#resolve()

But nowhere in the code does resolve() get called so I think substitution is just not going to work at all.

The typesafe docs recommend using ConfigFactory.load() because it will call resolve for you whereas we’re only doing a parse. I’ll try to submit a PR if it works.


#3

Raised PR: https://github.com/snowplow/snowplow/pull/2798 https://github.com/snowplow/kinesis-s3/pull/67


#4

Thanks @Shin! Much appreciated…


#5

Thx @Shin, i actually tried to do exactly that, but i always thought, i was doing it wrong. So i gave up on environment variables.