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"*/ +/*}*/