diff --git a/tfexec/destroy.go b/tfexec/destroy.go index 70cbf7a7..2f37c192 100644 --- a/tfexec/destroy.go +++ b/tfexec/destroy.go @@ -97,7 +97,7 @@ func (tf *Terraform) destroyCmd(ctx context.Context, opts ...DestroyOption) *exe o.configureDestroy(&c) } - args := []string{"destroy", "-no-color", "-auto-approve"} + args := []string{"destroy", "-no-color", "-auto-approve", "-input=false"} // string opts: only pass if set if c.backup != "" { diff --git a/tfexec/destroy_test.go b/tfexec/destroy_test.go index d6635ba9..9bfd576e 100644 --- a/tfexec/destroy_test.go +++ b/tfexec/destroy_test.go @@ -21,7 +21,7 @@ func TestDestroyCmd(t *testing.T) { actual := strings.TrimPrefix(cmdString(destroyCmd), destroyCmd.Path+" ") - expected := "destroy -no-color -auto-approve -lock-timeout=0s -lock=true -parallelism=10 -refresh=true" + expected := "destroy -no-color -auto-approve -input=false -lock-timeout=0s -lock=true -parallelism=10 -refresh=true" if actual != expected { t.Fatalf("expected default arguments of DestroyCmd:\n%s\n actual arguments:\n%s\n", expected, actual) @@ -32,7 +32,7 @@ func TestDestroyCmd(t *testing.T) { actual = strings.TrimPrefix(cmdString(destroyCmd), destroyCmd.Path+" ") - expected = "destroy -no-color -auto-approve -backup=testbackup -lock-timeout=200s -state=teststate -state-out=teststateout -var-file=testvarfile -lock=false -parallelism=99 -refresh=false -target=target1 -target=target2 -var 'var1=foo' -var 'var2=bar'" + expected = "destroy -no-color -auto-approve -input=false -backup=testbackup -lock-timeout=200s -state=teststate -state-out=teststateout -var-file=testvarfile -lock=false -parallelism=99 -refresh=false -target=target1 -target=target2 -var 'var1=foo' -var 'var2=bar'" if actual != expected { t.Fatalf("expected arguments of DestroyCmd:\n%s\n actual arguments:\n%s\n", expected, actual) diff --git a/tfexec/terraform_cmd.go b/tfexec/terraform_cmd.go index 3c18e040..7946069e 100644 --- a/tfexec/terraform_cmd.go +++ b/tfexec/terraform_cmd.go @@ -10,6 +10,9 @@ import ( const ( checkpointDisableEnvVar = "CHECKPOINT_DISABLE" logEnvVar = "TF_LOG" + inputEnvVar = "TF_INPUT" + automationEnvVar = "TF_IN_AUTOMATION" + logPathEnvVar = "TF_LOG_PATH" varEnvVarPrefix = "TF_VAR_" ) @@ -18,6 +21,9 @@ const ( // passed explicitly via SetEnv and are also elided when already existing // in the current environment. var prohibitedEnvVars = []string{ + inputEnvVar, + automationEnvVar, + logPathEnvVar, logEnvVar, } @@ -60,6 +66,7 @@ func (tf *Terraform) buildEnv() []string { } menv[logEnvVar] = "" // so logging can't pollute our stderr output + menv[automationEnvVar] = "1" env := []string{} for k, v := range menv { diff --git a/tfexec/terraform_test.go b/tfexec/terraform_test.go index 699f2b0c..52379cde 100644 --- a/tfexec/terraform_test.go +++ b/tfexec/terraform_test.go @@ -86,7 +86,7 @@ func TestCheckpointDisablePropagation(t *testing.T) { "FOOBAR": "1", }) initCmd := tf.initCmd(context.Background()) - expected := []string{"CHECKPOINT_DISABLE=1", "FOOBAR=1", "TF_LOG="} + expected := []string{"CHECKPOINT_DISABLE=1", "FOOBAR=1", "TF_IN_AUTOMATION=1", "TF_LOG=", "TF_LOG_PATH="} s := initCmd.Env sort.Strings(s) actual := s @@ -104,7 +104,7 @@ func TestCheckpointDisablePropagation(t *testing.T) { t.Fatal(err) } initCmd = tf.initCmd(context.Background()) - expected = []string{"CHECKPOINT_DISABLE=", "FOOBAR=1", "TF_LOG="} + expected = []string{"CHECKPOINT_DISABLE=", "FOOBAR=1", "TF_IN_AUTOMATION=1", "TF_LOG=", "TF_LOG_PATH="} s = initCmd.Env sort.Strings(s) actual = s