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

#1160 Specify -var-file before -var #1190

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/terraform/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ func FormatArgs(options *Options, args ...string) []string {
terraformArgs = append(terraformArgs, args...)

if includeVars {
terraformArgs = append(terraformArgs, FormatTerraformVarsAsArgs(options.Vars)...)
terraformArgs = append(terraformArgs, FormatTerraformArgs("-var-file", options.VarFiles)...)
terraformArgs = append(terraformArgs, FormatTerraformVarsAsArgs(options.Vars)...)
}

terraformArgs = append(terraformArgs, FormatTerraformArgs("-target", options.Targets)...)
Expand Down
21 changes: 21 additions & 0 deletions modules/terraform/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,24 @@ func TestFormatArgsAppliesLockCorrectly(t *testing.T) {
assert.Equal(t, testCase.expected, FormatArgs(&Options{}, testCase.command...))
}
}

func TestFormatArgsAppliesVarsFilesAndVarsCorrectly(t *testing.T) {
t.Parallel()

testCases := []struct {
varFile []string
vars map[string]interface{}
expected []string
}{
{[]string{}, map[string]interface{}{"foo": "bar"}, []string{"apply", "-var", "foo=bar", "-lock=false"}},
{[]string{"var_file.tfvars"}, map[string]interface{}{}, []string{"apply", "-var-file", "var_file.tfvars", "-lock=false"}},
{[]string{"var_file.tfvars"}, map[string]interface{}{"foo": "bar"}, []string{"apply", "-var-file", "var_file.tfvars", "-var", "foo=bar", "-lock=false"}},
}

for _, testCase := range testCases {
assert.Equal(t, testCase.expected, FormatArgs(&Options{
VarFiles: testCase.varFile,
Vars: testCase.vars,
}, "apply"))
}
}