Skip to content
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

Fully parse input variables from TF_VAR_ when validating during apply #36121

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
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.
  • Loading branch information
jbardin committed Nov 27, 2024
commit 4883499a8931931b71bfc4fbc088e1c2aecfec1f
17 changes: 5 additions & 12 deletions internal/command/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -964,16 +964,10 @@ func TestApply_planWithVarFileChangingVariableValue(t *testing.T) {
}
}

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

planPath := applyFixturePlanFile(t)
statePath := testTempFile(t)
Expand Down Expand Up @@ -1076,7 +1070,6 @@ foo = "bar"

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

args := []string{
"-state", statePath,
Expand Down Expand Up @@ -1168,7 +1161,7 @@ foo = "bar"

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

args := []string{
"-state", statePath,
Expand Down
5 changes: 5 additions & 0 deletions internal/command/testdata/apply-ephemeral-variable/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ variable "bar" {
ephemeral = true
}

variable "unused" {
type = map(string)
default = null
}

resource "test_instance" "foo" {
ami = "bar"
}
Loading