9

I would like to define in application.conf a variable which will be a list of strings. Currently in application.conf I have something like this:

some.env.variable = ["a", "b"]

I tried:

some.env.variable = ${?I_AM_ENV}.split(",")

when I_AM_ENV = a,b but it didn't work.

I get an error when loading app:

Wrong value type at 'some.env.variable', expecting: list but got: string
Mario Galic
  • 47,285
  • 6
  • 56
  • 98
Liza Shakury
  • 670
  • 9
  • 20

3 Answers3

7

Took a while but we found it.

application.conf

    access-control-allow-origin = ["http://localhost:4444"]
    access-control-allow-origin = ${?CLIENT_DOMAIN}
    export CLIENT_DOMAIN.0=http://localhost:3000
    export CLIENT_DOMAIN.1=http://localhost:3001
Marty
  • 174
  • 1
  • 9
  • This works, thanks! It seems the double declaration is required, but you can leave the first one empty if there's no reasonable default, e.g.: `foo = []` `foo = ${FOO}` `export FOO.0=bar` `export FOO.1=baz` – Alex Cruise Sep 16 '22 at 22:19
4

According to documentation:

// in your env
export OPTIONAL_A='"b", "c"'

// in application.conf
path = [ "a", ${?OPTIONAL_A} ]

should evaluate path to ["a", "b", "c"]

Mario Galic
  • 47,285
  • 6
  • 56
  • 98
1

The previous answers didn't work for me (using Play 2.6.17), so this answer did the trick: HOCON array substitution from envs (check the Maximum Flexibility section)

# Optionally set separated environment vars for each array item
export I_AM_ENV_0=a
export I_AM_ENV_1=b

Then, on application.conf, use substitution to set items within the array:

# it works also if the env. var. were not set
some.env.variable = [ ${?I_AM_ENV_0}, ${?I_AM_ENV_1} ]
Ricardo
  • 3,696
  • 5
  • 36
  • 50