terratest
terratest copied to clipboard
reorder of terraform arguments var and varFiles to reflect common usage
Switching the order of Vars and VarFiles in terraformArgs to reflect a more common scenario.
It's likely that a user would like to override one or two variables from a var-file using single variables, currently the behaviour is the opposite way round.
link to terraform variable precedence documentation.
Thanks for the PR! How did you test this? Could you add a test case that specifically verifies this behavior?
Hi I have just run into the same issue, given an expected order of vars and file-vars the expected precedence is not observed.
easy enough to set the variables 1 at a time, just a bit of duplication.
we have come across a new for this as well. But this PR has been open for quite some time, is there any chance this will be reviewed and actioned upon soon ?
I use -var-file to set the bulk of the variables, including defaults, and then would like to use -var to override them, for example to see what happens when a variable changes. This is currently not possible because changes provided via -var are clobbered by -var-file. Any chance you will accept this PR or provide an alternative soon?
Also hoping that this gets merged soon
@robmorgan there is a chance to merge this update?
If you locate your terraform.tfvars file in the same directory as the Terraform module you apply terraform.InitAndApply, then Terraform will automatically pick up on the variables defined in that file. You can then just use Vars to override the values set in your terraform.tfvars file:
terraformOptions := &terraform.Options{
TerraformDir: "../location/of/terraform/module/",
Vars: tfvarsOverridesGoHere,
}
As far as I was checking, this PR is not needed, because #1217 resolves issue with precedence - if you define SetVarsAfterVarFiles: true, then values passed in Vars take precedence over values from VarFiles e.g.:
terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
TerraformDir: ".",
VarFiles: []string{"example.tfvars"},
Vars: map[string]interface{}{
"example": "value_passed_from_test",
},
SetVarsAfterVarFiles: true,
})
closing as resolved in #1217