From 5d0e65f1c3ed84ebd32a3081c108ae75a4355702 Mon Sep 17 00:00:00 2001 From: chilledornaments Date: Thu, 15 Dec 2022 11:26:39 -0700 Subject: [PATCH 1/6] add logic for setting var options after var-file --- modules/terraform/format.go | 9 +- modules/terraform/format_test.go | 20 +++ modules/terraform/options.go | 1 + modules/terraform/workspace_test.go | 196 ++++++++++++++-------------- 4 files changed, 125 insertions(+), 101 deletions(-) diff --git a/modules/terraform/format.go b/modules/terraform/format.go index f50072d7c..35287d52c 100644 --- a/modules/terraform/format.go +++ b/modules/terraform/format.go @@ -56,8 +56,13 @@ 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)...) + if options.SetVarArgsLast { + terraformArgs = append(terraformArgs, FormatTerraformArgs("-var-file", options.VarFiles)...) + terraformArgs = append(terraformArgs, FormatTerraformVarsAsArgs(options.Vars)...) + } else { + terraformArgs = append(terraformArgs, FormatTerraformVarsAsArgs(options.Vars)...) + terraformArgs = append(terraformArgs, FormatTerraformArgs("-var-file", options.VarFiles)...) + } } terraformArgs = append(terraformArgs, FormatTerraformArgs("-target", options.Targets)...) diff --git a/modules/terraform/format_test.go b/modules/terraform/format_test.go index 3a2a325cb..e87ec98c1 100644 --- a/modules/terraform/format_test.go +++ b/modules/terraform/format_test.go @@ -278,3 +278,23 @@ func TestFormatArgsAppliesLockCorrectly(t *testing.T) { assert.Equal(t, testCase.expected, FormatArgs(&Options{}, testCase.command...)) } } + +func TestFormatSetVarArgsLastFormatsCorrectly(t *testing.T) { + t.Parallel() + + testCases := []struct { + command []string + vars map[string]interface{} + varFiles []string + setVarArgsLast bool + expected []string + }{ + {[]string{"plan"}, map[string]interface{}{"foo": "bar"}, []string{"test.tfvars"}, true, []string{"plan", "-var-file", "test.tfvars", "-var", "foo=bar", "-lock=false"}}, + {[]string{"plan"}, map[string]interface{}{"foo": "bar", "hello": "world"}, []string{"test.tfvars"}, true, []string{"plan", "-var-file", "test.tfvars", "-var", "foo=bar", "-var", "hello=world", "-lock=false"}}, + {[]string{"plan"}, map[string]interface{}{"foo": "bar", "hello": "world"}, []string{"test.tfvars"}, false, []string{"plan", "-var", "foo=bar", "-var", "hello=world", "-var-file", "test.tfvars", "-lock=false"}}, + } + + for _, testCase := range testCases { + assert.Equal(t, testCase.expected, FormatArgs(&Options{SetVarArgsLast: testCase.setVarArgsLast, Vars: testCase.vars, VarFiles: testCase.varFiles}, testCase.command...)) + } +} diff --git a/modules/terraform/options.go b/modules/terraform/options.go index 7ac78fdb6..5ac08a3eb 100644 --- a/modules/terraform/options.go +++ b/modules/terraform/options.go @@ -70,6 +70,7 @@ type Options struct { Parallelism int // Set the parallelism setting for Terraform PlanFilePath string // The path to output a plan file to (for the plan command) or read one from (for the apply command) PluginDir string // The path of downloaded plugins to pass to the terraform init command (-plugin-dir) + SetVarArgsLast bool // Pass -var options after -var-file options to Terraform commands } // Clone makes a deep copy of most fields on the Options object and returns it. diff --git a/modules/terraform/workspace_test.go b/modules/terraform/workspace_test.go index 0ccb3e752..6e8272961 100644 --- a/modules/terraform/workspace_test.go +++ b/modules/terraform/workspace_test.go @@ -1,12 +1,10 @@ package terraform import ( - "errors" "testing" "github.com/gruntwork-io/terratest/modules/files" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestWorkspaceNew(t *testing.T) { @@ -133,100 +131,100 @@ func TestNameMatchesWorkspace(t *testing.T) { } } -func TestWorkspaceDeleteE(t *testing.T) { - t.Parallel() - - // state describes an expected status when a given testCase begins - type state struct { - workspaces []string - current string - } - - // testCase describes a named test case with a state, args and expcted results - type testCase struct { - name string - initialState state - toDeleteWorkspace string - expectedCurrent string - expectedError error - } - - testCases := []testCase{ - { - name: "delete another existing workspace and stay on current", - initialState: state{ - workspaces: []string{"staging", "production"}, - current: "staging", - }, - toDeleteWorkspace: "production", - expectedCurrent: "staging", - expectedError: nil, - }, - { - name: "delete current workspace and switch to a specified", - initialState: state{ - workspaces: []string{"staging", "production"}, - current: "production", - }, - toDeleteWorkspace: "production", - expectedCurrent: "default", - expectedError: nil, - }, - { - name: "delete a non existing workspace should trigger an error", - initialState: state{ - workspaces: []string{"staging", "production"}, - current: "staging", - }, - toDeleteWorkspace: "hellothere", - expectedCurrent: "staging", - expectedError: WorkspaceDoesNotExist("hellothere"), - }, - { - name: "delete the default workspace triggers an error", - initialState: state{ - workspaces: []string{"staging", "production"}, - current: "staging", - }, - toDeleteWorkspace: "default", - expectedCurrent: "staging", - expectedError: &UnsupportedDefaultWorkspaceDeletion{}, - }, - } - - for _, testCase := range testCases { - testCase := testCase - t.Run(testCase.name, func(t *testing.T) { - t.Parallel() - testFolder, err := files.CopyTerraformFolderToTemp("../../test/fixtures/terraform-workspace", testCase.name) - require.NoError(t, err) - - options := &Options{ - TerraformDir: testFolder, - } - - // Set up pre-existing environment based on test case description - for _, existingWorkspace := range testCase.initialState.workspaces { - _, err = RunTerraformCommandE(t, options, "workspace", "new", existingWorkspace) - require.NoError(t, err) - } - // Switch to the specified workspace - _, err = RunTerraformCommandE(t, options, "workspace", "select", testCase.initialState.current) - require.NoError(t, err) - - // Testing time, wooohoooo - gotResult, gotErr := WorkspaceDeleteE(t, options, testCase.toDeleteWorkspace) - - // Check for errors - if testCase.expectedError != nil { - assert.True(t, errors.As(gotErr, &testCase.expectedError)) - } else { - assert.NoError(t, gotErr) - // Check for results - assert.Equal(t, testCase.expectedCurrent, gotResult) - assert.False(t, isExistingWorkspace(RunTerraformCommand(t, options, "workspace", "list"), testCase.toDeleteWorkspace)) - } - }) - - } -} +// func TestWorkspaceDeleteE(t *testing.T) { +// t.Parallel() + +// // state describes an expected status when a given testCase begins +// type state struct { +// workspaces []string +// current string +// } + +// // testCase describes a named test case with a state, args and expcted results +// type testCase struct { +// name string +// initialState state +// toDeleteWorkspace string +// expectedCurrent string +// expectedError error +// } + +// testCases := []testCase{ +// { +// name: "delete another existing workspace and stay on current", +// initialState: state{ +// workspaces: []string{"staging", "production"}, +// current: "staging", +// }, +// toDeleteWorkspace: "production", +// expectedCurrent: "staging", +// expectedError: nil, +// }, +// { +// name: "delete current workspace and switch to a specified", +// initialState: state{ +// workspaces: []string{"staging", "production"}, +// current: "production", +// }, +// toDeleteWorkspace: "production", +// expectedCurrent: "default", +// expectedError: nil, +// }, +// { +// name: "delete a non existing workspace should trigger an error", +// initialState: state{ +// workspaces: []string{"staging", "production"}, +// current: "staging", +// }, +// toDeleteWorkspace: "hellothere", +// expectedCurrent: "staging", +// expectedError: WorkspaceDoesNotExist("hellothere"), +// }, +// { +// name: "delete the default workspace triggers an error", +// initialState: state{ +// workspaces: []string{"staging", "production"}, +// current: "staging", +// }, +// toDeleteWorkspace: "default", +// expectedCurrent: "staging", +// expectedError: &UnsupportedDefaultWorkspaceDeletion{}, +// }, +// } + +// for _, testCase := range testCases { +// testCase := testCase +// t.Run(testCase.name, func(t *testing.T) { +// t.Parallel() +// testFolder, err := files.CopyTerraformFolderToTemp("../../test/fixtures/terraform-workspace", testCase.name) +// require.NoError(t, err) + +// options := &Options{ +// TerraformDir: testFolder, +// } + +// // Set up pre-existing environment based on test case description +// for _, existingWorkspace := range testCase.initialState.workspaces { +// _, err = RunTerraformCommandE(t, options, "workspace", "new", existingWorkspace) +// require.NoError(t, err) +// } +// // Switch to the specified workspace +// _, err = RunTerraformCommandE(t, options, "workspace", "select", testCase.initialState.current) +// require.NoError(t, err) + +// // Testing time, wooohoooo +// gotResult, gotErr := WorkspaceDeleteE(t, options, testCase.toDeleteWorkspace) + +// // Check for errors +// if testCase.expectedError != nil { +// assert.True(t, errors.As(gotErr, &testCase.expectedError)) +// } else { +// assert.NoError(t, gotErr) +// // Check for results +// assert.Equal(t, testCase.expectedCurrent, gotResult) +// assert.False(t, isExistingWorkspace(RunTerraformCommand(t, options, "workspace", "list"), testCase.toDeleteWorkspace)) +// } +// }) + +// } +// } From 56a2e8d8703af9e1e259e5d98ba8ab3e47b69ca2 Mon Sep 17 00:00:00 2001 From: chilledornaments Date: Thu, 15 Dec 2022 11:27:23 -0700 Subject: [PATCH 2/6] uncomment test --- modules/terraform/workspace_test.go | 196 ++++++++++++++-------------- 1 file changed, 99 insertions(+), 97 deletions(-) diff --git a/modules/terraform/workspace_test.go b/modules/terraform/workspace_test.go index 6e8272961..0ccb3e752 100644 --- a/modules/terraform/workspace_test.go +++ b/modules/terraform/workspace_test.go @@ -1,10 +1,12 @@ package terraform import ( + "errors" "testing" "github.com/gruntwork-io/terratest/modules/files" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestWorkspaceNew(t *testing.T) { @@ -131,100 +133,100 @@ func TestNameMatchesWorkspace(t *testing.T) { } } -// func TestWorkspaceDeleteE(t *testing.T) { -// t.Parallel() - -// // state describes an expected status when a given testCase begins -// type state struct { -// workspaces []string -// current string -// } - -// // testCase describes a named test case with a state, args and expcted results -// type testCase struct { -// name string -// initialState state -// toDeleteWorkspace string -// expectedCurrent string -// expectedError error -// } - -// testCases := []testCase{ -// { -// name: "delete another existing workspace and stay on current", -// initialState: state{ -// workspaces: []string{"staging", "production"}, -// current: "staging", -// }, -// toDeleteWorkspace: "production", -// expectedCurrent: "staging", -// expectedError: nil, -// }, -// { -// name: "delete current workspace and switch to a specified", -// initialState: state{ -// workspaces: []string{"staging", "production"}, -// current: "production", -// }, -// toDeleteWorkspace: "production", -// expectedCurrent: "default", -// expectedError: nil, -// }, -// { -// name: "delete a non existing workspace should trigger an error", -// initialState: state{ -// workspaces: []string{"staging", "production"}, -// current: "staging", -// }, -// toDeleteWorkspace: "hellothere", -// expectedCurrent: "staging", -// expectedError: WorkspaceDoesNotExist("hellothere"), -// }, -// { -// name: "delete the default workspace triggers an error", -// initialState: state{ -// workspaces: []string{"staging", "production"}, -// current: "staging", -// }, -// toDeleteWorkspace: "default", -// expectedCurrent: "staging", -// expectedError: &UnsupportedDefaultWorkspaceDeletion{}, -// }, -// } - -// for _, testCase := range testCases { -// testCase := testCase -// t.Run(testCase.name, func(t *testing.T) { -// t.Parallel() -// testFolder, err := files.CopyTerraformFolderToTemp("../../test/fixtures/terraform-workspace", testCase.name) -// require.NoError(t, err) - -// options := &Options{ -// TerraformDir: testFolder, -// } - -// // Set up pre-existing environment based on test case description -// for _, existingWorkspace := range testCase.initialState.workspaces { -// _, err = RunTerraformCommandE(t, options, "workspace", "new", existingWorkspace) -// require.NoError(t, err) -// } -// // Switch to the specified workspace -// _, err = RunTerraformCommandE(t, options, "workspace", "select", testCase.initialState.current) -// require.NoError(t, err) - -// // Testing time, wooohoooo -// gotResult, gotErr := WorkspaceDeleteE(t, options, testCase.toDeleteWorkspace) - -// // Check for errors -// if testCase.expectedError != nil { -// assert.True(t, errors.As(gotErr, &testCase.expectedError)) -// } else { -// assert.NoError(t, gotErr) -// // Check for results -// assert.Equal(t, testCase.expectedCurrent, gotResult) -// assert.False(t, isExistingWorkspace(RunTerraformCommand(t, options, "workspace", "list"), testCase.toDeleteWorkspace)) -// } -// }) - -// } -// } +func TestWorkspaceDeleteE(t *testing.T) { + t.Parallel() + + // state describes an expected status when a given testCase begins + type state struct { + workspaces []string + current string + } + + // testCase describes a named test case with a state, args and expcted results + type testCase struct { + name string + initialState state + toDeleteWorkspace string + expectedCurrent string + expectedError error + } + + testCases := []testCase{ + { + name: "delete another existing workspace and stay on current", + initialState: state{ + workspaces: []string{"staging", "production"}, + current: "staging", + }, + toDeleteWorkspace: "production", + expectedCurrent: "staging", + expectedError: nil, + }, + { + name: "delete current workspace and switch to a specified", + initialState: state{ + workspaces: []string{"staging", "production"}, + current: "production", + }, + toDeleteWorkspace: "production", + expectedCurrent: "default", + expectedError: nil, + }, + { + name: "delete a non existing workspace should trigger an error", + initialState: state{ + workspaces: []string{"staging", "production"}, + current: "staging", + }, + toDeleteWorkspace: "hellothere", + expectedCurrent: "staging", + expectedError: WorkspaceDoesNotExist("hellothere"), + }, + { + name: "delete the default workspace triggers an error", + initialState: state{ + workspaces: []string{"staging", "production"}, + current: "staging", + }, + toDeleteWorkspace: "default", + expectedCurrent: "staging", + expectedError: &UnsupportedDefaultWorkspaceDeletion{}, + }, + } + + for _, testCase := range testCases { + testCase := testCase + t.Run(testCase.name, func(t *testing.T) { + t.Parallel() + testFolder, err := files.CopyTerraformFolderToTemp("../../test/fixtures/terraform-workspace", testCase.name) + require.NoError(t, err) + + options := &Options{ + TerraformDir: testFolder, + } + + // Set up pre-existing environment based on test case description + for _, existingWorkspace := range testCase.initialState.workspaces { + _, err = RunTerraformCommandE(t, options, "workspace", "new", existingWorkspace) + require.NoError(t, err) + } + // Switch to the specified workspace + _, err = RunTerraformCommandE(t, options, "workspace", "select", testCase.initialState.current) + require.NoError(t, err) + + // Testing time, wooohoooo + gotResult, gotErr := WorkspaceDeleteE(t, options, testCase.toDeleteWorkspace) + + // Check for errors + if testCase.expectedError != nil { + assert.True(t, errors.As(gotErr, &testCase.expectedError)) + } else { + assert.NoError(t, gotErr) + // Check for results + assert.Equal(t, testCase.expectedCurrent, gotResult) + assert.False(t, isExistingWorkspace(RunTerraformCommand(t, options, "workspace", "list"), testCase.toDeleteWorkspace)) + } + }) + + } +} From cdc0dc457afeeb1ac5982a3b5314a78df3f9a624 Mon Sep 17 00:00:00 2001 From: chilledornaments Date: Thu, 15 Dec 2022 11:41:53 -0700 Subject: [PATCH 3/6] rename field --- modules/terraform/format.go | 2 +- modules/terraform/format_test.go | 14 +++++++------- modules/terraform/options.go | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/terraform/format.go b/modules/terraform/format.go index 35287d52c..7b6293a58 100644 --- a/modules/terraform/format.go +++ b/modules/terraform/format.go @@ -56,7 +56,7 @@ func FormatArgs(options *Options, args ...string) []string { terraformArgs = append(terraformArgs, args...) if includeVars { - if options.SetVarArgsLast { + if options.SetVarsAfterVarFiles { terraformArgs = append(terraformArgs, FormatTerraformArgs("-var-file", options.VarFiles)...) terraformArgs = append(terraformArgs, FormatTerraformVarsAsArgs(options.Vars)...) } else { diff --git a/modules/terraform/format_test.go b/modules/terraform/format_test.go index e87ec98c1..e82ad8e07 100644 --- a/modules/terraform/format_test.go +++ b/modules/terraform/format_test.go @@ -279,15 +279,15 @@ func TestFormatArgsAppliesLockCorrectly(t *testing.T) { } } -func TestFormatSetVarArgsLastFormatsCorrectly(t *testing.T) { +func TestFormatSetVarsAfterVarFilesFormatsCorrectly(t *testing.T) { t.Parallel() testCases := []struct { - command []string - vars map[string]interface{} - varFiles []string - setVarArgsLast bool - expected []string + command []string + vars map[string]interface{} + varFiles []string + setVarsAfterVarFiles bool + expected []string }{ {[]string{"plan"}, map[string]interface{}{"foo": "bar"}, []string{"test.tfvars"}, true, []string{"plan", "-var-file", "test.tfvars", "-var", "foo=bar", "-lock=false"}}, {[]string{"plan"}, map[string]interface{}{"foo": "bar", "hello": "world"}, []string{"test.tfvars"}, true, []string{"plan", "-var-file", "test.tfvars", "-var", "foo=bar", "-var", "hello=world", "-lock=false"}}, @@ -295,6 +295,6 @@ func TestFormatSetVarArgsLastFormatsCorrectly(t *testing.T) { } for _, testCase := range testCases { - assert.Equal(t, testCase.expected, FormatArgs(&Options{SetVarArgsLast: testCase.setVarArgsLast, Vars: testCase.vars, VarFiles: testCase.varFiles}, testCase.command...)) + assert.Equal(t, testCase.expected, FormatArgs(&Options{SetVarsAfterVarFiles: testCase.setVarsAfterVarFiles, Vars: testCase.vars, VarFiles: testCase.varFiles}, testCase.command...)) } } diff --git a/modules/terraform/options.go b/modules/terraform/options.go index 5ac08a3eb..9495a6c09 100644 --- a/modules/terraform/options.go +++ b/modules/terraform/options.go @@ -70,7 +70,7 @@ type Options struct { Parallelism int // Set the parallelism setting for Terraform PlanFilePath string // The path to output a plan file to (for the plan command) or read one from (for the apply command) PluginDir string // The path of downloaded plugins to pass to the terraform init command (-plugin-dir) - SetVarArgsLast bool // Pass -var options after -var-file options to Terraform commands + SetVarsAfterVarFiles bool // Pass -var options after -var-file options to Terraform commands } // Clone makes a deep copy of most fields on the Options object and returns it. From c308bf7c037136996ce741b1e0cb20f6e6cb3d52 Mon Sep 17 00:00:00 2001 From: chilledornaments Date: Thu, 15 Dec 2022 14:40:24 -0700 Subject: [PATCH 4/6] fix test expectations, add test case --- modules/terraform/format_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/terraform/format_test.go b/modules/terraform/format_test.go index e82ad8e07..8337d8b78 100644 --- a/modules/terraform/format_test.go +++ b/modules/terraform/format_test.go @@ -292,6 +292,7 @@ func TestFormatSetVarsAfterVarFilesFormatsCorrectly(t *testing.T) { {[]string{"plan"}, map[string]interface{}{"foo": "bar"}, []string{"test.tfvars"}, true, []string{"plan", "-var-file", "test.tfvars", "-var", "foo=bar", "-lock=false"}}, {[]string{"plan"}, map[string]interface{}{"foo": "bar", "hello": "world"}, []string{"test.tfvars"}, true, []string{"plan", "-var-file", "test.tfvars", "-var", "foo=bar", "-var", "hello=world", "-lock=false"}}, {[]string{"plan"}, map[string]interface{}{"foo": "bar", "hello": "world"}, []string{"test.tfvars"}, false, []string{"plan", "-var", "foo=bar", "-var", "hello=world", "-var-file", "test.tfvars", "-lock=false"}}, + {[]string{"plan"}, map[string]interface{}{"foo": "bar"}, []string{"test.tfvars"}, false, []string{"plan", "-var", "foo=bar", "-var-file", "test.tfvars", "-lock=false"}}, } for _, testCase := range testCases { From 7da6e5e399d08f972eb17a47a1b8fec4908524f7 Mon Sep 17 00:00:00 2001 From: chilledornaments Date: Fri, 16 Dec 2022 11:25:17 -0700 Subject: [PATCH 5/6] utilize checkResultWithRetry func for tests --- modules/terraform/format_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/terraform/format_test.go b/modules/terraform/format_test.go index 8337d8b78..372fd1f9d 100644 --- a/modules/terraform/format_test.go +++ b/modules/terraform/format_test.go @@ -295,7 +295,9 @@ func TestFormatSetVarsAfterVarFilesFormatsCorrectly(t *testing.T) { {[]string{"plan"}, map[string]interface{}{"foo": "bar"}, []string{"test.tfvars"}, false, []string{"plan", "-var", "foo=bar", "-var-file", "test.tfvars", "-lock=false"}}, } - for _, testCase := range testCases { - assert.Equal(t, testCase.expected, FormatArgs(&Options{SetVarsAfterVarFiles: testCase.setVarsAfterVarFiles, Vars: testCase.vars, VarFiles: testCase.varFiles}, testCase.command...)) + for idx, testCase := range testCases { + checkResultWithRetry(t, 100, testCase.expected, fmt.Sprintf("FormatArgs(%d)", idx), func() interface{} { + return FormatArgs(&Options{SetVarsAfterVarFiles: testCase.setVarsAfterVarFiles, Vars: testCase.vars, VarFiles: testCase.varFiles}, testCase.command...) + }) } } From cee5e91d6646ec75dd31cb12851642d09068d6b1 Mon Sep 17 00:00:00 2001 From: chilledornaments Date: Sun, 18 Dec 2022 14:16:04 -0700 Subject: [PATCH 6/6] refactor test logic to compare index --- modules/terraform/format_test.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/modules/terraform/format_test.go b/modules/terraform/format_test.go index 372fd1f9d..99409053d 100644 --- a/modules/terraform/format_test.go +++ b/modules/terraform/format_test.go @@ -295,9 +295,20 @@ func TestFormatSetVarsAfterVarFilesFormatsCorrectly(t *testing.T) { {[]string{"plan"}, map[string]interface{}{"foo": "bar"}, []string{"test.tfvars"}, false, []string{"plan", "-var", "foo=bar", "-var-file", "test.tfvars", "-lock=false"}}, } - for idx, testCase := range testCases { - checkResultWithRetry(t, 100, testCase.expected, fmt.Sprintf("FormatArgs(%d)", idx), func() interface{} { - return FormatArgs(&Options{SetVarsAfterVarFiles: testCase.setVarsAfterVarFiles, Vars: testCase.vars, VarFiles: testCase.varFiles}, testCase.command...) - }) + for _, testCase := range testCases { + result := FormatArgs(&Options{SetVarsAfterVarFiles: testCase.setVarsAfterVarFiles, Vars: testCase.vars, VarFiles: testCase.varFiles}, testCase.command...) + + // Make sure that -var and -var-file options are in the expected order relative to each other + // Note that the order of the different -var and -var-file options may change + // See this comment for more info: https://github.com/gruntwork-io/terratest/blob/6fb86056797e3e62ebdd9011ba26605e0976a6f8/modules/terraform/format_test.go#L123-L142 + for idx, arg := range result { + if arg == "-var-file" || arg == "-var" { + assert.Equal(t, testCase.expected[idx], arg) + } + } + + // Make sure that the order of other arguments hasn't been incorrectly modified + assert.Equal(t, testCase.expected[0], result[0]) + assert.Equal(t, testCase.expected[len(testCase.expected)-1], result[len(result)-1]) } }