Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reorder of terraform arguments var and varFiles to reflect common usage #256

Closed
wants to merge 1 commit into from

Conversation

matt-smith
Copy link

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.

@brikis98
Copy link
Member

Thanks for the PR! How did you test this? Could you add a test case that specifically verifies this behavior?

@jimusbobus
Copy link

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.

Copy link

@jhaood jhaood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix is high priority for my test code. We need to override our global vars in a var-file with command line -var arguments.

Thank you for the PR.

@aldojimenez
Copy link

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 ?

@Nuru
Copy link

Nuru commented Feb 26, 2022

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?

@archetypalsxe
Copy link

Also hoping that this gets merged soon

@pimielowski
Copy link

@robmorgan there is a chance to merge this update?

@tobias-edwards
Copy link

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,
}

@sebastianczech
Copy link

sebastianczech commented Jan 5, 2023

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,
})

@matt-smith
Copy link
Author

closing as resolved in #1217

@matt-smith matt-smith closed this Mar 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants