Skip to content

Fix terraform command generation in different order #4322

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

Open
wants to merge 5 commits 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
3 changes: 2 additions & 1 deletion cli/commands/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,8 @@ func FilterTerraformExtraArgs(l log.Logger, opts *options.TerragruntOptions, ter
for _, arg := range terragruntConfig.Terraform.ExtraArgs {
for _, argCmd := range arg.Commands {
if cmd == argCmd {
lastArg := opts.TerraformCliArgs.Last()
lastArg := opts.TerraformCliArgs.CommandNameN(1)

skipVars := (cmd == tf.CommandNameApply || cmd == tf.CommandNameDestroy) && util.IsFile(lastArg)

// The following is a fix for GH-493.
Expand Down
6 changes: 6 additions & 0 deletions cli/commands/run/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,12 @@ func TestFilterTerraformExtraArgs(t *testing.T) {
mockExtraArgs([]string{"--foo", "-var-file=test.tfvars", "bar", "-var='key=value'", "foo"}, []string{"plan", "apply"}, []string{"required.tfvars"}, []string{temporaryFile}),
[]string{"--foo", "bar", "foo"},
},
// apply with some parameters, providing a file in a different order => no var files included
{
mockCmdOptions(t, workingDir, []string{"apply", temporaryFile, "-no-color", "-foo"}),
mockExtraArgs([]string{"--foo", "-var-file=test.tfvars", "bar", "-var='key=value'", "foo"}, []string{"plan", "apply"}, []string{"required.tfvars"}, []string{temporaryFile}),
[]string{"--foo", "bar", "foo"},
},
// destroy providing a folder, var files should stay included
{
mockCmdOptions(t, workingDir, []string{"destroy", workingDir}),
Expand Down
Loading