diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index 96dd8ad5c..a5e12e2d3 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -2145,6 +2145,57 @@ func TestContext2Apply_destroyNestedModule(t *testing.T) { } } +func TestContext2Apply_destroyDeeplyNestedModule(t *testing.T) { + m := testModule(t, "apply-destroy-deeply-nested-module") + p := testProvider("aws") + p.ApplyFn = testApplyFn + p.DiffFn = testDiffFn + + s := &State{ + Modules: []*ModuleState{ + &ModuleState{ + Path: []string{"root", "child", "subchild", "subsubchild"}, + Resources: map[string]*ResourceState{ + "aws_instance.bar": &ResourceState{ + Type: "aws_instance", + Primary: &InstanceState{ + ID: "bar", + }, + }, + }, + }, + }, + } + + ctx := testContext2(t, &ContextOpts{ + Module: m, + Providers: map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + State: s, + }) + + // First plan and apply a create operation + if _, err := ctx.Plan(); err != nil { + t.Fatalf("err: %s", err) + } + + state, err := ctx.Apply() + if err != nil { + t.Fatalf("err: %s", err) + } + + // Test that things were destroyed + actual := strings.TrimSpace(state.String()) + expected := strings.TrimSpace(` +module.child.subchild.subsubchild: + + `) + if actual != expected { + t.Fatalf("bad: \n%s", actual) + } +} + func TestContext2Apply_destroyOutputs(t *testing.T) { m := testModule(t, "apply-destroy-outputs") h := new(HookRecordApplyOrder) diff --git a/terraform/test-fixtures/apply-destroy-deeply-nested-module/child/main.tf b/terraform/test-fixtures/apply-destroy-deeply-nested-module/child/main.tf new file mode 100644 index 000000000..3694951f5 --- /dev/null +++ b/terraform/test-fixtures/apply-destroy-deeply-nested-module/child/main.tf @@ -0,0 +1,3 @@ +module "subchild" { + source = "./subchild" +} diff --git a/terraform/test-fixtures/apply-destroy-deeply-nested-module/child/subchild/main.tf b/terraform/test-fixtures/apply-destroy-deeply-nested-module/child/subchild/main.tf new file mode 100644 index 000000000..d31b87e0c --- /dev/null +++ b/terraform/test-fixtures/apply-destroy-deeply-nested-module/child/subchild/main.tf @@ -0,0 +1,5 @@ +/* +module "subsubchild" { + source = "./subsubchild" +} +*/ diff --git a/terraform/test-fixtures/apply-destroy-deeply-nested-module/child/subchild/subsubchild/main.tf b/terraform/test-fixtures/apply-destroy-deeply-nested-module/child/subchild/subsubchild/main.tf new file mode 100644 index 000000000..6ff716a4d --- /dev/null +++ b/terraform/test-fixtures/apply-destroy-deeply-nested-module/child/subchild/subsubchild/main.tf @@ -0,0 +1 @@ +resource "aws_instance" "bar" {} diff --git a/terraform/test-fixtures/apply-destroy-deeply-nested-module/main.tf b/terraform/test-fixtures/apply-destroy-deeply-nested-module/main.tf new file mode 100644 index 000000000..1f95749fa --- /dev/null +++ b/terraform/test-fixtures/apply-destroy-deeply-nested-module/main.tf @@ -0,0 +1,3 @@ +module "child" { + source = "./child" +}