diff --git a/internal/command/apply_test.go b/internal/command/apply_test.go index 9082178cc4..d66aaf8d1f 100644 --- a/internal/command/apply_test.go +++ b/internal/command/apply_test.go @@ -1046,7 +1046,7 @@ func TestApply_planVarsEphemeral_applyTime(t *testing.T) { } }) - // Finally, test that the apply also fails if we do *not* supply a value for + // Test that the apply also fails if we do *not* supply a value for // the apply-time variable foo. t.Run("missing ephemeral variable", func(t *testing.T) { view, done = testView(t) @@ -1066,6 +1066,47 @@ func TestApply_planVarsEphemeral_applyTime(t *testing.T) { t.Fatal("should've failed: ", output.Stdout()) } }) + + t.Run("passing ephemeral variable through vars file", func(t *testing.T) { + view, done = testView(t) + c = &ApplyCommand{ + Meta: Meta{ + testingOverrides: metaOverridesForProvider(p), + View: view, + }, + } + const planVarFile = ` +foo = "bar" +` + + // Write a tfvars file with the variable + tfVarsPath := testVarsFile(t) + err := os.WriteFile(tfVarsPath, []byte(planVarFile), 0600) + if err != nil { + t.Fatalf("Could not write vars file %e", err) + } + + args = []string{ + "-state", statePath, + "-var-file", tfVarsPath, + planPath, + } + code = c.Run(args) + output = done(t) + if code != 0 { + t.Fatal("should've succeeded: ", output.Stderr()) + } + }) + + t.Run("passing ephemeral variable through environment variable", func(t *testing.T) { + // https://github.com/hashicorp/terraform/blob/b21a5703bdc0af3d7730c0b8b9f68e41a4bc9645/internal/command/meta_vars.go#L95 + t.Skip("TODO") + }) + + t.Run("passing ephemeral variable through interactive prompts", func(t *testing.T) { + // Look at https://github.com/hashicorp/terraform/blob/b21a5703bdc0af3d7730c0b8b9f68e41a4bc9645/internal/command/plan_test.go#L794 for inspiration + t.Skip("TODO") + }) } // we should be able to apply a plan file with no other file dependencies diff --git a/internal/command/command_test.go b/internal/command/command_test.go index 563c74479a..023e349625 100644 --- a/internal/command/command_test.go +++ b/internal/command/command_test.go @@ -553,6 +553,12 @@ func testTempFile(t *testing.T) string { return filepath.Join(testTempDir(t), "state.tfstate") } +func testVarsFile(t *testing.T) string { + t.Helper() + + return filepath.Join(testTempDir(t), "variables.tfvars") +} + func testTempDir(t *testing.T) string { t.Helper() d, err := filepath.EvalSymlinks(t.TempDir())