Skip to content

Commit

Permalink
Add additional automation env vars
Browse files Browse the repository at this point in the history
Also add missing -input=false for Destroy
  • Loading branch information
paultyng committed Jul 20, 2020
1 parent cda2340 commit 71751e5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tfexec/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down
4 changes: 2 additions & 2 deletions tfexec/destroy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions tfexec/terraform_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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_"
)
Expand All @@ -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,
}

Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions tfexec/terraform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 71751e5

Please sign in to comment.