From 7d6472dad0ca5f50a8e299ebdf860af5b4d82f4a Mon Sep 17 00:00:00 2001 From: James Bardin Date: Thu, 10 Sep 2020 16:49:46 -0400 Subject: [PATCH] use plan state in contextOptsForPlanViaFile --- terraform/context_apply_test.go | 26 ++++++++++++-------------- terraform/context_test.go | 4 ++-- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index 70e4285cc6..4deda63152 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -2376,12 +2376,10 @@ func TestContext2Apply_provisionerInterpCount(t *testing.T) { t.Fatalf("plan failed unexpectedly: %s", diags.Err()) } - state := ctx.State() - // We'll marshal and unmarshal the plan here, to ensure that we have // a clean new context as would be created if we separately ran // terraform plan -out=tfplan && terraform apply tfplan - ctxOpts, err := contextOptsForPlanViaFile(snap, state, plan) + ctxOpts, err := contextOptsForPlanViaFile(snap, plan) if err != nil { t.Fatal(err) } @@ -6014,7 +6012,7 @@ func TestContext2Apply_destroyModuleWithAttrsReferencingResource(t *testing.T) { t.Logf("Step 2 plan: %s", legacyDiffComparisonString(plan.Changes)) - ctxOpts, err := contextOptsForPlanViaFile(snap, state, plan) + ctxOpts, err := contextOptsForPlanViaFile(snap, plan) if err != nil { t.Fatalf("failed to round-trip through planfile: %s", err) } @@ -6089,7 +6087,7 @@ func TestContext2Apply_destroyWithModuleVariableAndCount(t *testing.T) { t.Fatalf("destroy plan err: %s", diags.Err()) } - ctxOpts, err := contextOptsForPlanViaFile(snap, state, plan) + ctxOpts, err := contextOptsForPlanViaFile(snap, plan) if err != nil { t.Fatalf("failed to round-trip through planfile: %s", err) } @@ -6245,7 +6243,7 @@ func TestContext2Apply_destroyWithModuleVariableAndCountNested(t *testing.T) { t.Fatalf("destroy plan err: %s", diags.Err()) } - ctxOpts, err := contextOptsForPlanViaFile(snap, state, plan) + ctxOpts, err := contextOptsForPlanViaFile(snap, plan) if err != nil { t.Fatalf("failed to round-trip through planfile: %s", err) } @@ -8319,7 +8317,7 @@ func TestContext2Apply_issue7824(t *testing.T) { } // Write / Read plan to simulate running it through a Plan file - ctxOpts, err := contextOptsForPlanViaFile(snap, ctx.State(), plan) + ctxOpts, err := contextOptsForPlanViaFile(snap, plan) if err != nil { t.Fatalf("failed to round-trip through planfile: %s", err) } @@ -8396,7 +8394,7 @@ func TestContext2Apply_issue5254(t *testing.T) { } // Write / Read plan to simulate running it through a Plan file - ctxOpts, err := contextOptsForPlanViaFile(snap, state, plan) + ctxOpts, err := contextOptsForPlanViaFile(snap, plan) if err != nil { t.Fatalf("failed to round-trip through planfile: %s", err) } @@ -8473,7 +8471,7 @@ func TestContext2Apply_targetedWithTaintedInState(t *testing.T) { } // Write / Read plan to simulate running it through a Plan file - ctxOpts, err := contextOptsForPlanViaFile(snap, ctx.State(), plan) + ctxOpts, err := contextOptsForPlanViaFile(snap, plan) if err != nil { t.Fatalf("failed to round-trip through planfile: %s", err) } @@ -8730,7 +8728,7 @@ func TestContext2Apply_destroyNestedModuleWithAttrsReferencingResource(t *testin t.Fatalf("destroy plan err: %s", diags.Err()) } - ctxOpts, err := contextOptsForPlanViaFile(snap, state, plan) + ctxOpts, err := contextOptsForPlanViaFile(snap, plan) if err != nil { t.Fatalf("failed to round-trip through planfile: %s", err) } @@ -9313,7 +9311,7 @@ func TestContext2Apply_plannedInterpolatedCount(t *testing.T) { // We'll marshal and unmarshal the plan here, to ensure that we have // a clean new context as would be created if we separately ran // terraform plan -out=tfplan && terraform apply tfplan - ctxOpts, err := contextOptsForPlanViaFile(snap, ctx.State(), plan) + ctxOpts, err := contextOptsForPlanViaFile(snap, plan) if err != nil { t.Fatalf("failed to round-trip through planfile: %s", err) } @@ -9376,7 +9374,7 @@ func TestContext2Apply_plannedDestroyInterpolatedCount(t *testing.T) { // We'll marshal and unmarshal the plan here, to ensure that we have // a clean new context as would be created if we separately ran // terraform plan -out=tfplan && terraform apply tfplan - ctxOpts, err := contextOptsForPlanViaFile(snap, ctx.State(), plan) + ctxOpts, err := contextOptsForPlanViaFile(snap, plan) if err != nil { t.Fatalf("failed to round-trip through planfile: %s", err) } @@ -9826,7 +9824,7 @@ func TestContext2Apply_destroyDataCycle(t *testing.T) { // We'll marshal and unmarshal the plan here, to ensure that we have // a clean new context as would be created if we separately ran // terraform plan -out=tfplan && terraform apply tfplan - ctxOpts, err := contextOptsForPlanViaFile(snap, state, plan) + ctxOpts, err := contextOptsForPlanViaFile(snap, plan) if err != nil { t.Fatal(err) } @@ -10141,7 +10139,7 @@ func TestContext2Apply_cbdCycle(t *testing.T) { // We'll marshal and unmarshal the plan here, to ensure that we have // a clean new context as would be created if we separately ran // terraform plan -out=tfplan && terraform apply tfplan - ctxOpts, err := contextOptsForPlanViaFile(snap, state, plan) + ctxOpts, err := contextOptsForPlanViaFile(snap, plan) if err != nil { t.Fatal(err) } diff --git a/terraform/context_test.go b/terraform/context_test.go index f071a2afa9..a07e275e2a 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -749,7 +749,7 @@ func testProviderSchema(name string) *ProviderSchema { // our context tests try to exercise lots of stuff at once and so having them // round-trip things through on-disk files is often an important part of // fully representing an old bug in a regression test. -func contextOptsForPlanViaFile(configSnap *configload.Snapshot, state *states.State, plan *plans.Plan) (*ContextOpts, error) { +func contextOptsForPlanViaFile(configSnap *configload.Snapshot, plan *plans.Plan) (*ContextOpts, error) { dir, err := ioutil.TempDir("", "terraform-contextForPlanViaFile") if err != nil { return nil, err @@ -760,7 +760,7 @@ func contextOptsForPlanViaFile(configSnap *configload.Snapshot, state *states.St // to run through any of the codepaths that care about Lineage/Serial/etc // here anyway. stateFile := &statefile.File{ - State: state, + State: plan.State, } // To make life a little easier for test authors, we'll populate a simple