diff --git a/terraform/context_plan_test.go b/terraform/context_plan_test.go index 302b64402..c791b8b5c 100644 --- a/terraform/context_plan_test.go +++ b/terraform/context_plan_test.go @@ -2703,3 +2703,39 @@ func TestContext2Plan_moduleVariableFromSplat(t *testing.T) { t.Fatalf("bad:\n%s\n\nexpected\n\n%s", actual, expected) } } + +func TestContext2Plan_createBeforeDestroy_depends_datasource(t *testing.T) { + m := testModule(t, "plan-cdb-depends-datasource") + p := testProvider("aws") + p.DiffFn = testDiffFn + ctx := testContext2(t, &ContextOpts{ + Module: m, + Providers: map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + }) + + plan, err := ctx.Plan() + if err != nil { + t.Fatalf("err: %s", err) + } + + if got := len(plan.Diff.Modules); got != 1 { + t.Fatalf("got %d modules; want 1", got) + } + + moduleDiff := plan.Diff.Modules[0] + + if _, ok := moduleDiff.Resources["aws_instance.foo.0"]; !ok { + t.Fatalf("missing diff for aws_instance.foo.0") + } + if _, ok := moduleDiff.Resources["aws_instance.foo.1"]; !ok { + t.Fatalf("missing diff for aws_instance.foo.1") + } + if _, ok := moduleDiff.Resources["data.aws_vpc.bar.0"]; !ok { + t.Fatalf("missing diff for data.aws_vpc.bar.0") + } + if _, ok := moduleDiff.Resources["data.aws_vpc.bar.1"]; !ok { + t.Fatalf("missing diff for data.aws_vpc.bar.1") + } +} diff --git a/terraform/test-fixtures/plan-cdb-depends-datasource/main.tf b/terraform/test-fixtures/plan-cdb-depends-datasource/main.tf new file mode 100644 index 000000000..3deae1f8b --- /dev/null +++ b/terraform/test-fixtures/plan-cdb-depends-datasource/main.tf @@ -0,0 +1,11 @@ +resource "aws_instance" "foo" { + count = 2 + num = "2" + compute = "${element(data.aws_vpc.bar.*.id, count.index)}" + lifecycle { create_before_destroy = true } +} + +data "aws_vpc" "bar" { + count = 2 + foo = "${count.index}" +}