How to pass environmental variables in envconsul config file? How to pass environmental variables in envconsul config file? kubernetes kubernetes

How to pass environmental variables in envconsul config file?


I. Within container specification set environmental variables (values in double quotes):

env:  - name: VAULT_TOKEN    value: "abcd1234"  - name: VAULT_ADDR    value: "http://10.0.2.2:8200"

Then refer to the values in envconsul.hcl

vault {  address = ${VAULT_ADDR}  renew_token = false  retry {    backoff = "1s"  }  token = ${VAULT_TOKEN}}

II. Another option is to unseal the vault cluster (with the unseal key which was printed while initializing the vault cluster)

$ vault operator unseal

and then authenticate to the vault cluster using a root token.

$ vault login <your-generated-root-token>

More details


I tried many suggestions and nothing worked until I passed -vault-token argument to envconsul command like this:

envconsul -vault-token=$VAULT_TOKEN -config=/app/config.hcl -secret="/secret/debug/service" env

and in config.hcl it should be like this:

 vault {  address     = "http://kvstorage.try.direct:8200"  token       = "${env(VAULT_TOKEN)}" }