From bfb770ee89aeed066c99e40fd525757bb1b37488 Mon Sep 17 00:00:00 2001 From: James Nugent Date: Wed, 11 Nov 2015 12:35:35 -0500 Subject: [PATCH] Add failing test for targeted destroy on orphan This replicates the issue reported in #3852. --- terraform/context_plan_test.go | 47 +++++++++++++++++++ .../plan-targeted-orphan/main.tf | 6 +++ 2 files changed, 53 insertions(+) create mode 100644 terraform/test-fixtures/plan-targeted-orphan/main.tf diff --git a/terraform/context_plan_test.go b/terraform/context_plan_test.go index db6f24577..e91fc7747 100644 --- a/terraform/context_plan_test.go +++ b/terraform/context_plan_test.go @@ -1627,6 +1627,53 @@ STATE: } } +func TestContext2Plan_targetedOrphan(t *testing.T) { + m := testModule(t, "plan-targeted-orphan") + p := testProvider("aws") + p.DiffFn = testDiffFn + ctx := testContext2(t, &ContextOpts{ + Module: m, + Providers: map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + State: &State{ + Modules: []*ModuleState{ + &ModuleState{ + Path: rootModulePath, + Resources: map[string]*ResourceState{ + "aws_instance.orphan": &ResourceState{ + Type: "aws_instance", + Primary: &InstanceState{ + ID: "i-789xyz", + }, + }, + }, + }, + }, + }, + Destroy: true, + Targets: []string{"aws_instance.orphan"}, + }) + + plan, err := ctx.Plan() + if err != nil { + t.Fatalf("err: %s", err) + } + + actual := strings.TrimSpace(plan.String()) + expected := strings.TrimSpace(`DIFF: + +DESTROY: aws_instance.orphan + +STATE: + +aws_instance.orphan: + ID = i-789xyz`) + if actual != expected { + t.Fatalf("expected:\n%s\n\ngot:\n%s", expected, actual) + } +} + func TestContext2Plan_provider(t *testing.T) { m := testModule(t, "plan-provider") p := testProvider("aws") diff --git a/terraform/test-fixtures/plan-targeted-orphan/main.tf b/terraform/test-fixtures/plan-targeted-orphan/main.tf new file mode 100644 index 000000000..f2020858b --- /dev/null +++ b/terraform/test-fixtures/plan-targeted-orphan/main.tf @@ -0,0 +1,6 @@ +# This resource was previously "created" and the fixture represents +# it being destroyed subsequently + +/*resource "aws_instance" "orphan" {*/ + /*foo = "bar"*/ +/*}*/