Allows undeclared variables from named files (-var-file=...) #21697
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Rationale
Many people use terraform together with terragrunt or other tools.
With terragrunt specifically, a common project structure can be as follows:
Here,
ecs-cluster
andecs-service
are terragrunt modules.The files
common.tfvars
are plugged together with correctenv.tfvars
depending on the environment as var files:This allows setting some variables globally for the project, plus it makes it possible to override them in
env.tfvars
or on per-module basis.However, some modules don't have all variables declared, for example
ecs-service
module doesn't need to declare a variable likeecs_cluster_instance_type
, because it doesn't use it. But it is convenient to set it inenv.vars
to make it a source of configuration for this environment, rather than setting variables in every module folder.Since terraform 0.12 there is a warning for every undeclared variable, which can get really messy if you use it with terragrunt:
I actually raised this some time ago: gruntwork-io/terragrunt#466 (comment)
To make it work in the current state, some nasty hacks has to be introduced as per gruntwork-io/terragrunt#737 like having terragrunt to convert variables to env vars.
Instead, this PR just allows undeclared variables set via named files.
Plus adds a few more test cases to check for other undeclared var sources.