diff --git a/terraform/test-fixtures/transform-destroy-edge-module-only/child/main.tf b/terraform/test-fixtures/transform-destroy-edge-module-only/child/main.tf new file mode 100644 index 000000000..2ae3859a8 --- /dev/null +++ b/terraform/test-fixtures/transform-destroy-edge-module-only/child/main.tf @@ -0,0 +1,8 @@ +resource "aws_instance" "a" {} +resource "aws_instance" "b" { + value = "${aws_instance.a.id}" +} + +resource "aws_instance" "c" { + value = "${aws_instance.b.id}" +} diff --git a/terraform/test-fixtures/transform-destroy-edge-module-only/main.tf b/terraform/test-fixtures/transform-destroy-edge-module-only/main.tf new file mode 100644 index 000000000..0f6991c53 --- /dev/null +++ b/terraform/test-fixtures/transform-destroy-edge-module-only/main.tf @@ -0,0 +1,3 @@ +module "child" { + source = "./child" +} diff --git a/terraform/transform_attach_state.go b/terraform/transform_attach_state.go index b69d2f962..564ff08f1 100644 --- a/terraform/transform_attach_state.go +++ b/terraform/transform_attach_state.go @@ -45,12 +45,11 @@ func (t *AttachStateTransformer) Transform(g *Graph) error { } // Attach the first resource state we get - log.Printf("SEARCH: %s", addr) found := false for _, result := range results { if rs, ok := result.Value.(*ResourceState); ok { log.Printf( - "[DEBUG] Attaching resource state to %q: %s", + "[DEBUG] Attaching resource state to %q: %#v", dag.VertexName(v), rs) an.AttachResourceState(rs) found = true diff --git a/terraform/transform_destroy_edge_test.go b/terraform/transform_destroy_edge_test.go index 1f7b1a5d6..a0792493c 100644 --- a/terraform/transform_destroy_edge_test.go +++ b/terraform/transform_destroy_edge_test.go @@ -96,6 +96,32 @@ func TestDestroyEdgeTransformer_module(t *testing.T) { } } +func TestDestroyEdgeTransformer_moduleOnly(t *testing.T) { + g := Graph{Path: RootModulePath} + g.Add(&graphNodeDestroyerTest{AddrString: "module.child.aws_instance.a"}) + g.Add(&graphNodeDestroyerTest{AddrString: "module.child.aws_instance.b"}) + g.Add(&graphNodeDestroyerTest{AddrString: "module.child.aws_instance.c"}) + tf := &DestroyEdgeTransformer{ + Module: testModule(t, "transform-destroy-edge-module-only"), + } + if err := tf.Transform(&g); err != nil { + t.Fatalf("err: %s", err) + } + + actual := strings.TrimSpace(g.String()) + expected := strings.TrimSpace(` +module.child.aws_instance.a (destroy) + module.child.aws_instance.b (destroy) + module.child.aws_instance.c (destroy) +module.child.aws_instance.b (destroy) + module.child.aws_instance.c (destroy) +module.child.aws_instance.c (destroy) +`) + if actual != expected { + t.Fatalf("bad:\n\n%s", actual) + } +} + type graphNodeCreatorTest struct { AddrString string Refs []string