diff --git a/terraform/graph_test.go b/terraform/graph_test.go index a9b8194e5..c7ea931f6 100644 --- a/terraform/graph_test.go +++ b/terraform/graph_test.go @@ -731,6 +731,42 @@ func TestGraphAddDiff_module(t *testing.T) { } } +func TestGraphAddDiff_module_depends(t *testing.T) { + m := testModule(t, "graph-diff-module-dep") + diff := &Diff{ + Modules: []*ModuleDiff{ + &ModuleDiff{ + Path: rootModulePath, + Resources: map[string]*InstanceDiff{ + "aws_instance.foo": &InstanceDiff{ + Destroy: true, + }, + }, + }, + &ModuleDiff{ + Path: []string{"root", "child"}, + Destroy: true, + Resources: map[string]*InstanceDiff{ + "aws_instance.foo": &InstanceDiff{ + Destroy: true, + }, + }, + }, + }, + } + + g, err := Graph(&GraphOpts{Module: m, Diff: diff}) + if err != nil { + t.Fatalf("err: %s", err) + } + + actual := strings.TrimSpace(g.String()) + expected := strings.TrimSpace(testTerraformGraphDiffModuleDependsStr) + if actual != expected { + t.Fatalf("bad:\n\n%s", actual) + } +} + func TestGraphAddDiff_createBeforeDestroy(t *testing.T) { m := testModule(t, "graph-diff-create-before") diff := &Diff{ @@ -1214,6 +1250,18 @@ root root -> module.child ` +const testTerraformGraphDiffModuleDependsStr = ` +root: root +aws_instance.foo + aws_instance.foo -> aws_instance.foo (destroy) +aws_instance.foo (destroy) + aws_instance.foo (destroy) -> module.child +module.child +root + root -> aws_instance.foo + root -> module.child +` + const testTerraformGraphModulesStr = ` root: root aws_instance.web diff --git a/terraform/test-fixtures/graph-diff-module-dep/child/main.tf b/terraform/test-fixtures/graph-diff-module-dep/child/main.tf new file mode 100644 index 000000000..84d1de905 --- /dev/null +++ b/terraform/test-fixtures/graph-diff-module-dep/child/main.tf @@ -0,0 +1,5 @@ +resource "aws_instance" "foo" {} + +output "bar" { + value = "baz" +} diff --git a/terraform/test-fixtures/graph-diff-module-dep/main.tf b/terraform/test-fixtures/graph-diff-module-dep/main.tf new file mode 100644 index 000000000..2f61386b2 --- /dev/null +++ b/terraform/test-fixtures/graph-diff-module-dep/main.tf @@ -0,0 +1,8 @@ +resource "aws_instance" "foo" {} + +module "child" { + source = "./child" + in = "${aws_instance.foo.id}" +} + +