Rory
Rory

Reputation: 838

How to provide an array of values as an env variable to typesafe/lightbend config?

How do I provide an array/list of values as an environment variable to typesafe/lightbend config?

application.conf

default-buckets = [
      10,
      30,
      100,
      300,
      1000,
      3000,
      10000,
      30000,
      100000
    ]
default-buckets = [${?DEFAULT_BUCKETS}]

So, I'd like to pass something like this as an environment variable to be able to override the defaults:

DEFAULT_BUCKETS=1000,3000

However, I'm getting the following error:

com.typesafe.config.ConfigException$WrongType: env variables: buckets.default-buckets has type list of STRING rather than list of NUMBER

Is this possible without having to have my application code deal with it by e.g. calling split(',')?

Upvotes: 7

Views: 3268

Answers (2)

Patryk Celiński
Patryk Celiński

Reputation: 57

default-buckets = [
  ${?DEFAULT_BUCKETS_1},
  ${?DEFAULT_BUCKETS_2},
  ${?DEFAULT_BUCKETS_3},
  ${?DEFAULT_BUCKETS_4},
  ${?DEFAULT_BUCKETS_5}
]

For

DEFAULT_BUCKETS_1=10
DEFAULT_BUCKETS_2=30
DEFAULT_BUCKETS_5=100

Results in

TestConfig(List(10, 30, 100))

Upvotes: 1

airudah
airudah

Reputation: 1179

As far as I'm aware, there's no simple way to pass a list of environment variable to override an array of conf values.

You will have to set env vars like so:

export DEFAULT_BUCKETS_1=1000
export DEFAULT_BUCKETS_2=3000

Then pass them into the conf file:

default-buckets = []
default-buckets.0 = ${?DEFAULT_BUCKETS_1}
default-buckets.1 = ${?DEFAULT_BUCKETS_2}

Upvotes: 2

Related Questions