From 7eac9e1d8911ec0a482e38194f08f5eb155ff5b0 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Thu, 10 Dec 2020 09:44:22 -0500 Subject: [PATCH] set SkipRefresh for plan and apply The option is set in the same place for plan and apply. --- backend/local/backend_apply_test.go | 24 ++++++++++++++++++++++++ backend/local/backend_local.go | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/backend/local/backend_apply_test.go b/backend/local/backend_apply_test.go index 73c384d42..adf7c08fe 100644 --- a/backend/local/backend_apply_test.go +++ b/backend/local/backend_apply_test.go @@ -241,6 +241,30 @@ test_instance.foo: assertBackendStateUnlocked(t, b) } +func TestLocal_applyRefreshFalse(t *testing.T) { + b, cleanup := TestLocal(t) + defer cleanup() + + p := TestLocalProvider(t, b, "test", planFixtureSchema()) + testStateFile(t, b.StatePath, testPlanState()) + + op, configCleanup := testOperationApply(t, "./testdata/plan") + defer configCleanup() + + run, err := b.Operation(context.Background(), op) + if err != nil { + t.Fatalf("bad: %s", err) + } + <-run.Done() + if run.Result != backend.OperationSuccess { + t.Fatalf("plan operation failed") + } + + if p.ReadResourceCalled { + t.Fatal("ReadResource should not be called") + } +} + type backendWithFailingState struct { Local } diff --git a/backend/local/backend_local.go b/backend/local/backend_local.go index b4d6002c0..1b67939af 100644 --- a/backend/local/backend_local.go +++ b/backend/local/backend_local.go @@ -78,7 +78,7 @@ func (b *Local) context(op *backend.Operation) (*terraform.Context, *configload. opts.Targets = op.Targets opts.UIInput = op.UIIn - opts.SkipRefresh = op.Type == backend.OperationTypePlan && !op.PlanRefresh + opts.SkipRefresh = op.Type != backend.OperationTypeRefresh && !op.PlanRefresh if opts.SkipRefresh { log.Printf("[DEBUG] backend/local: skipping refresh of managed resources") }