From f29046037fc21bb4cec6ceed33b7420f4cdecbd6 Mon Sep 17 00:00:00 2001 From: Daniel Banck Date: Tue, 31 Mar 2026 12:37:03 +0200 Subject: [PATCH] Add regression test for apply with vars Running an apply from a plan should not raise diagnostics for missing variables. All non-ephemeral variables are already available in the planfile. --- internal/command/apply_test.go | 53 ++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/internal/command/apply_test.go b/internal/command/apply_test.go index 5581647a27..6871327e4e 100644 --- a/internal/command/apply_test.go +++ b/internal/command/apply_test.go @@ -1123,6 +1123,59 @@ func TestApply_plan_remoteState(t *testing.T) { } } +func TestApply_planWithVars(t *testing.T) { + // Regression test for apply with a plan file that includes variables, + // to ensure that apply doesn't prompt for the variables + tDir := testTempDir(t) + + // The value of foo is the same as in the var file + planPath := applyFixturePlanFileWithVariableValue(t, "bar") + statePath := testTempFile(t) + + t.Chdir(tDir) + + p := applyFixtureProvider() + p.GetProviderSchemaResponse = &providers.GetProviderSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ + "test_instance": { + Body: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Computed: true}, + "value": {Type: cty.String, Optional: true}, + }, + }, + }, + }, + } + + view, done := testView(t) + c := &ApplyCommand{ + Meta: Meta{ + testingOverrides: metaOverridesForProvider(p), + View: view, + }, + } + + args := []string{ + "-state-out", statePath, + planPath, + } + code := c.Run(args) + output := done(t) + if code != 0 { + t.Fatalf("bad: %d\n\n%s", code, output.Stderr()) + } + + if _, err := os.Stat(statePath); err != nil { + t.Fatalf("err: %s", err) + } + + state := testStateRead(t, statePath) + if state == nil { + t.Fatal("state should not be nil") + } +} + func TestApply_planWithVarFile(t *testing.T) { varFileDir := testTempDir(t) varFilePath := filepath.Join(varFileDir, "terraform.tfvars")