Terragrunt: allow get_env() to work without a "default" argument

Created on 7 Dec 2017  路  5Comments  路  Source: gruntwork-io/terragrunt

Hi,

I'm using get_env() to wrap some environment variables expected by some modules with a different name, as follows :

    extra_arguments "env_var_mapping" {
      commands = ["${get_terraform_commands_that_need_vars()}"]
        arguments = ["-var", "my_var=${get_env("VAR_NAME")}"]
    }

I'm willingly using get_env() without the DEFAULT argument as I wan't terraform to warn/abort if the associated variable is not provided.

The thing is that Terragrunt does not currently support thus and complains:
Invalid parameters. Expected syntax of the form '${get_env("VAR_NAME", "default")}', but got '"VAR_NAME"'

Of course I could pass variables prefixed by TF_VAR_ but i'd like to have the freedom not to name env variables following the name of variables expected by terraform modules, hence the use of terragrunt here.
Rationales for env var remapping:

  • the naming of a terraform variable can be relevant in the context of a module, but could lack sense in the context of a whole app
  • the same variable name could be used by several modules deployed at the same time by the same cicd job

What do you think of allowing the use of get_env() helper without the default argument ?
(or do you have an alternative in mind ?)

enhancement help wanted

Most helpful comment

A big +1 on this. I've hit the exact same issue with variables such as password that need to be set across different environments. A PR for this would be very welcome.

All 5 comments

A big +1 on this. I've hit the exact same issue with variables such as password that need to be set across different environments. A PR for this would be very welcome.

hey @brikis98 !
Provide me with a starting point and I could handle this i guess, it should not be too difficult.

do we have any updates for this?

@ozbillwang we had discussions with @brikis98 on the proper way to do it (see: https://github.com/gruntwork-io/terragrunt/pull/393) but then i got caught by somethingelse, and do not use the get_env() helper in the end.
Feel free to resume the PR

Was this page helpful?
0 / 5 - 0 ratings