terratest icon indicating copy to clipboard operation
terratest copied to clipboard

Question: Change order of passing variables in InitAndApply

Open tomarv2 opened this issue 4 years ago • 3 comments

This call:

terraform.InitAndApply(t, terraformOptions)

parses vars and var-file and does apply, I want to see if there is a way to change the order, I want -var-file to go first and -var to go after, as far as I know, the last one overrides the previous value.

The reason: there can be common variables in the file and a user would want to override them as needed in tests.

Current order:

terraform [apply -input=false -auto-approve -var prjid=demo-ecs-E9p9SV -var teamid=test -var-file xyz.tfvars -lock=false]

Expected order:

terraform [apply -input=false -auto-approve -var-file xyz.tfvars -var prjid=demo-ecs-E9p9SV -var teamid=test -lock=false]

tomarv2 avatar Sep 11 '20 17:09 tomarv2

Related to: https://github.com/gruntwork-io/terratest/pull/256

tomarv2 avatar Sep 11 '20 17:09 tomarv2

Hm, I don't think simply swapping the order is the right answer, as I'm sure there are users who prefer the current order too. So is there a way to allow users to specify the order?

brikis98 avatar Sep 13 '20 11:09 brikis98

I suspect that if one is sensitive to the order of how the varfile and vars are passed in, it makes more sense to manually construct the list of args using an ExtraArgs type option variable. It does add redundancy to the API, but I think is more robust to the use cases where the exact order of args matters.

yorinasub17 avatar Sep 14 '20 14:09 yorinasub17