From 620f04af731d66f32d590c469e044fad6c726eb5 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Thu, 27 Sep 2018 18:17:06 -0700 Subject: [PATCH] core: Fix TestContext2Plan_moduleVariableFromSplat The weird special-case behaviors of testDiffFn were interfering with the outcome of this test, but we don't actually need any of those special behaviors here so we'll use a very simple PlanResourceChangeFn implementation instead, just letting the built-in merge behavior in core take care of it. --- terraform/context_plan_test.go | 78 ++++++++++--------- .../plan-cbd-depends-datasource/main.tf | 4 +- 2 files changed, 44 insertions(+), 38 deletions(-) diff --git a/terraform/context_plan_test.go b/terraform/context_plan_test.go index 4c7ab83b8..64428fc74 100644 --- a/terraform/context_plan_test.go +++ b/terraform/context_plan_test.go @@ -4874,7 +4874,6 @@ func TestContext2Plan_moduleVariableFromSplat(t *testing.T) { func TestContext2Plan_createBeforeDestroy_depends_datasource(t *testing.T) { m := testModule(t, "plan-cbd-depends-datasource") p := testProvider("aws") - p.DiffFn = testDiffFn p.GetSchemaReturn = &ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { @@ -4893,6 +4892,11 @@ func TestContext2Plan_createBeforeDestroy_depends_datasource(t *testing.T) { }, }, } + p.PlanResourceChangeFn = func (req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse { + return providers.PlanResourceChangeResponse{ + PlannedState: req.ProposedNewState, + } + } ctx := testContext2(t, &ContextOpts{ Config: m, @@ -4922,42 +4926,44 @@ func TestContext2Plan_createBeforeDestroy_depends_datasource(t *testing.T) { t.Fatal(err) } - switch i := ric.Addr.String(); i { - case "aws_instance.foo[0]": - if res.Action != plans.Create { - t.Fatalf("resource %s should be created, got %s", ric.Addr, ric.Action) + t.Run(ric.Addr.String(), func (t *testing.T) { + switch i := ric.Addr.String(); i { + case "aws_instance.foo[0]": + if res.Action != plans.Create { + t.Fatalf("resource %s should be created, got %s", ric.Addr, ric.Action) + } + checkVals(t, objectVal(t, schema, map[string]cty.Value{ + "num": cty.StringVal("2"), + "computed": cty.UnknownVal(cty.String), + }), ric.After) + case "aws_instance.foo[1]": + if res.Action != plans.Create { + t.Fatalf("resource %s should be created, got %s", ric.Addr, ric.Action) + } + checkVals(t, objectVal(t, schema, map[string]cty.Value{ + "num": cty.StringVal("2"), + "computed": cty.UnknownVal(cty.String), + }), ric.After) + case "data.aws_vpc.bar[0]": + if res.Action != plans.Read { + t.Fatalf("resource %s should be read, got %s", ric.Addr, ric.Action) + } + checkVals(t, objectVal(t, schema, map[string]cty.Value{ + "id": cty.UnknownVal(cty.String), + "foo": cty.StringVal("0"), + }), ric.After) + case "data.aws_vpc.bar[1]": + if res.Action != plans.Read { + t.Fatalf("resource %s should be read, got %s", ric.Addr, ric.Action) + } + checkVals(t, objectVal(t, schema, map[string]cty.Value{ + "id": cty.UnknownVal(cty.String), + "foo": cty.StringVal("1"), + }), ric.After) + default: + t.Fatal("unknown instance:", i) } - checkVals(t, objectVal(t, schema, map[string]cty.Value{ - "num": cty.StringVal("2"), - "computed": cty.UnknownVal(cty.String), - }), ric.After) - case "aws_instance.foo[1]": - if res.Action != plans.Create { - t.Fatalf("resource %s should be created, got %s", ric.Addr, ric.Action) - } - checkVals(t, objectVal(t, schema, map[string]cty.Value{ - "num": cty.StringVal("2"), - "computed": cty.UnknownVal(cty.String), - }), ric.After) - case "data.aws_vpc.bar[0]": - if res.Action != plans.Read { - t.Fatalf("resource %s should be read, got %s", ric.Addr, ric.Action) - } - checkVals(t, objectVal(t, schema, map[string]cty.Value{ - "id": cty.UnknownVal(cty.String), - "foo": cty.StringVal("0"), - }), ric.After) - case "data.aws_vpc.bar[1]": - if res.Action != plans.Read { - t.Fatalf("resource %s should be read, got %s", ric.Addr, ric.Action) - } - checkVals(t, objectVal(t, schema, map[string]cty.Value{ - "id": cty.UnknownVal(cty.String), - "foo": cty.StringVal("1"), - }), ric.After) - default: - t.Fatal("unknown instance:", i) - } + }) } } diff --git a/terraform/test-fixtures/plan-cbd-depends-datasource/main.tf b/terraform/test-fixtures/plan-cbd-depends-datasource/main.tf index 1292e5444..b523204a8 100644 --- a/terraform/test-fixtures/plan-cbd-depends-datasource/main.tf +++ b/terraform/test-fixtures/plan-cbd-depends-datasource/main.tf @@ -1,6 +1,6 @@ resource "aws_instance" "foo" { - count = 2 - num = "2" + count = 2 + num = "2" computed = data.aws_vpc.bar[count.index].id lifecycle {