use plan state in contextOptsForPlanViaFile

This commit is contained in:
James Bardin 2020-09-10 16:49:46 -04:00
parent 908217acc4
commit 7d6472dad0
2 changed files with 14 additions and 16 deletions

View File

@ -2376,12 +2376,10 @@ func TestContext2Apply_provisionerInterpCount(t *testing.T) {
t.Fatalf("plan failed unexpectedly: %s", diags.Err()) t.Fatalf("plan failed unexpectedly: %s", diags.Err())
} }
state := ctx.State()
// We'll marshal and unmarshal the plan here, to ensure that we have // 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 // a clean new context as would be created if we separately ran
// terraform plan -out=tfplan && terraform apply tfplan // terraform plan -out=tfplan && terraform apply tfplan
ctxOpts, err := contextOptsForPlanViaFile(snap, state, plan) ctxOpts, err := contextOptsForPlanViaFile(snap, plan)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -6014,7 +6012,7 @@ func TestContext2Apply_destroyModuleWithAttrsReferencingResource(t *testing.T) {
t.Logf("Step 2 plan: %s", legacyDiffComparisonString(plan.Changes)) t.Logf("Step 2 plan: %s", legacyDiffComparisonString(plan.Changes))
ctxOpts, err := contextOptsForPlanViaFile(snap, state, plan) ctxOpts, err := contextOptsForPlanViaFile(snap, plan)
if err != nil { if err != nil {
t.Fatalf("failed to round-trip through planfile: %s", err) 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()) t.Fatalf("destroy plan err: %s", diags.Err())
} }
ctxOpts, err := contextOptsForPlanViaFile(snap, state, plan) ctxOpts, err := contextOptsForPlanViaFile(snap, plan)
if err != nil { if err != nil {
t.Fatalf("failed to round-trip through planfile: %s", err) 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()) t.Fatalf("destroy plan err: %s", diags.Err())
} }
ctxOpts, err := contextOptsForPlanViaFile(snap, state, plan) ctxOpts, err := contextOptsForPlanViaFile(snap, plan)
if err != nil { if err != nil {
t.Fatalf("failed to round-trip through planfile: %s", err) 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 // 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 { if err != nil {
t.Fatalf("failed to round-trip through planfile: %s", err) 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 // 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 { if err != nil {
t.Fatalf("failed to round-trip through planfile: %s", err) 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 // 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 { if err != nil {
t.Fatalf("failed to round-trip through planfile: %s", err) 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()) t.Fatalf("destroy plan err: %s", diags.Err())
} }
ctxOpts, err := contextOptsForPlanViaFile(snap, state, plan) ctxOpts, err := contextOptsForPlanViaFile(snap, plan)
if err != nil { if err != nil {
t.Fatalf("failed to round-trip through planfile: %s", err) 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 // 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 // a clean new context as would be created if we separately ran
// terraform plan -out=tfplan && terraform apply tfplan // terraform plan -out=tfplan && terraform apply tfplan
ctxOpts, err := contextOptsForPlanViaFile(snap, ctx.State(), plan) ctxOpts, err := contextOptsForPlanViaFile(snap, plan)
if err != nil { if err != nil {
t.Fatalf("failed to round-trip through planfile: %s", err) 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 // 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 // a clean new context as would be created if we separately ran
// terraform plan -out=tfplan && terraform apply tfplan // terraform plan -out=tfplan && terraform apply tfplan
ctxOpts, err := contextOptsForPlanViaFile(snap, ctx.State(), plan) ctxOpts, err := contextOptsForPlanViaFile(snap, plan)
if err != nil { if err != nil {
t.Fatalf("failed to round-trip through planfile: %s", err) 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 // 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 // a clean new context as would be created if we separately ran
// terraform plan -out=tfplan && terraform apply tfplan // terraform plan -out=tfplan && terraform apply tfplan
ctxOpts, err := contextOptsForPlanViaFile(snap, state, plan) ctxOpts, err := contextOptsForPlanViaFile(snap, plan)
if err != nil { if err != nil {
t.Fatal(err) 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 // 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 // a clean new context as would be created if we separately ran
// terraform plan -out=tfplan && terraform apply tfplan // terraform plan -out=tfplan && terraform apply tfplan
ctxOpts, err := contextOptsForPlanViaFile(snap, state, plan) ctxOpts, err := contextOptsForPlanViaFile(snap, plan)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -749,7 +749,7 @@ func testProviderSchema(name string) *ProviderSchema {
// our context tests try to exercise lots of stuff at once and so having them // 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 // round-trip things through on-disk files is often an important part of
// fully representing an old bug in a regression test. // 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") dir, err := ioutil.TempDir("", "terraform-contextForPlanViaFile")
if err != nil { if err != nil {
return nil, err 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 // to run through any of the codepaths that care about Lineage/Serial/etc
// here anyway. // here anyway.
stateFile := &statefile.File{ stateFile := &statefile.File{
State: state, State: plan.State,
} }
// To make life a little easier for test authors, we'll populate a simple // To make life a little easier for test authors, we'll populate a simple