Skip to content

Commit 4883499

Browse files
committed
test non-string env var input variables
Non-string input variables taken from the environment initially need to be parsed and stored as string, since there is no type associated type information. Make sure these are correctly handled when validated during apply.
1 parent 0027d16 commit 4883499

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

internal/command/apply_test.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -964,16 +964,10 @@ func TestApply_planWithVarFileChangingVariableValue(t *testing.T) {
964964
}
965965
}
966966

967-
func TestApply_planVars(t *testing.T) {
968-
// This test ensures that it isn't allowed to set non-ephemeral input
969-
// variables when applying from a saved plan file, since in that case the
970-
// variable values come from the saved plan file.
971-
//
972-
// This situation was originally checked by the apply command itself,
973-
// and that's what this test was originally exercising. This rule
974-
// is now enforced by the "local" backend instead, but this test
975-
// is still valid since the command instance delegates to the
976-
// local backend.
967+
func TestApply_planUndeclaredVars(t *testing.T) {
968+
// This test ensures that it isn't allowed to set undeclared input variables
969+
// when applying from a saved plan file, since in that case the variable
970+
// values come from the saved plan file.
977971

978972
planPath := applyFixturePlanFile(t)
979973
statePath := testTempFile(t)
@@ -1076,7 +1070,6 @@ foo = "bar"
10761070

10771071
"with planfile passing ephemeral variable through environment variable": func(t *testing.T, c *ApplyCommand, statePath, planPath string, done func(*testing.T) *terminal.TestOutput) {
10781072
t.Setenv("TF_VAR_foo", "bar")
1079-
defer t.Setenv("TF_VAR_foo", "")
10801073

10811074
args := []string{
10821075
"-state", statePath,
@@ -1168,7 +1161,7 @@ foo = "bar"
11681161

11691162
"without planfile passing ephemeral variable through environment variable": func(t *testing.T, c *ApplyCommand, statePath, planPath string, done func(*testing.T) *terminal.TestOutput) {
11701163
t.Setenv("TF_VAR_foo", "bar")
1171-
defer t.Setenv("TF_VAR_foo", "")
1164+
t.Setenv("TF_VAR_unused", `{key:"val"}`)
11721165

11731166
args := []string{
11741167
"-state", statePath,

internal/command/testdata/apply-ephemeral-variable/main.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ variable "bar" {
99
ephemeral = true
1010
}
1111

12+
variable "unused" {
13+
type = map(string)
14+
default = null
15+
}
16+
1217
resource "test_instance" "foo" {
1318
ami = "bar"
1419
}

0 commit comments

Comments
 (0)