diff --git a/terraform/context_test.go b/terraform/context_test.go index c547ec2da..4045217ab 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -2861,6 +2861,35 @@ func TestContextPlan(t *testing.T) { } } +func TestContextPlan_emptyDiff(t *testing.T) { + m := testModule(t, "plan-empty") + p := testProvider("aws") + p.DiffFn = func( + info *InstanceInfo, + s *InstanceState, + c *ResourceConfig) (*InstanceDiff, error) { + return nil, nil + } + + ctx := testContext(t, &ContextOpts{ + Module: m, + Providers: map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + }) + + plan, err := ctx.Plan(nil) + if err != nil { + t.Fatalf("err: %s", err) + } + + actual := strings.TrimSpace(plan.String()) + expected := strings.TrimSpace(testTerraformPlanEmptyStr) + if actual != expected { + t.Fatalf("bad:\n%s", actual) + } +} + func TestContextPlan_minimal(t *testing.T) { m := testModule(t, "plan-empty") p := testProvider("aws") diff --git a/terraform/graph_test.go b/terraform/graph_test.go index 4f87e245b..c966f5f31 100644 --- a/terraform/graph_test.go +++ b/terraform/graph_test.go @@ -786,6 +786,77 @@ func TestGraphAddDiff_module_depends(t *testing.T) { } } +func TestGraphAddDiff_moduleDependsModule(t *testing.T) { + m := testModule(t, "graph-diff-module-dep-module") + diff := &Diff{ + Modules: []*ModuleDiff{ + &ModuleDiff{ + Path: []string{"root"}, + Destroy: true, + }, + &ModuleDiff{ + Path: []string{"root", "foo"}, + Destroy: true, + Resources: map[string]*InstanceDiff{ + "aws_instance.foo": &InstanceDiff{ + Destroy: true, + }, + }, + }, + &ModuleDiff{ + Path: []string{"root", "bar"}, + Destroy: true, + Resources: map[string]*InstanceDiff{ + "aws_instance.foo": &InstanceDiff{ + Destroy: true, + }, + }, + }, + }, + } + state := &State{ + Modules: []*ModuleState{ + &ModuleState{ + Path: []string{"root", "foo"}, + Resources: map[string]*ResourceState{ + "aws_instance.foo": &ResourceState{ + Type: "aws_instance", + Primary: &InstanceState{ + ID: "foo", + }, + }, + }, + }, + + &ModuleState{ + Path: []string{"root", "bar"}, + Resources: map[string]*ResourceState{ + "aws_instance.foo": &ResourceState{ + Type: "aws_instance", + Primary: &InstanceState{ + ID: "foo", + }, + }, + }, + Dependencies: []string{ + "module.foo", + }, + }, + }, + } + + g, err := Graph(&GraphOpts{Module: m, Diff: diff, State: state}) + if err != nil { + t.Fatalf("err: %s", err) + } + + actual := strings.TrimSpace(g.String()) + expected := strings.TrimSpace(testTerraformGraphDiffModuleDependsModuleStr) + 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{ @@ -1345,6 +1416,16 @@ root root -> module.orphan ` +const testTerraformGraphDiffModuleDependsModuleStr = ` +root: root +module.bar +module.foo + module.foo -> module.bar +root + root -> module.bar + root -> module.foo +` + const testTerraformGraphModulesStr = ` root: root aws_instance.web diff --git a/terraform/test-fixtures/graph-diff-module-dep-module/bar/main.tf b/terraform/test-fixtures/graph-diff-module-dep-module/bar/main.tf new file mode 100644 index 000000000..6f71b621f --- /dev/null +++ b/terraform/test-fixtures/graph-diff-module-dep-module/bar/main.tf @@ -0,0 +1,3 @@ +variable "in" {} + +aws_instance "foo" {} diff --git a/terraform/test-fixtures/graph-diff-module-dep-module/foo/main.tf b/terraform/test-fixtures/graph-diff-module-dep-module/foo/main.tf new file mode 100644 index 000000000..2bf29d59e --- /dev/null +++ b/terraform/test-fixtures/graph-diff-module-dep-module/foo/main.tf @@ -0,0 +1,5 @@ +output "data" { + value = "foo" +} + +aws_instance "foo" {} diff --git a/terraform/test-fixtures/graph-diff-module-dep-module/main.tf b/terraform/test-fixtures/graph-diff-module-dep-module/main.tf new file mode 100644 index 000000000..656503f28 --- /dev/null +++ b/terraform/test-fixtures/graph-diff-module-dep-module/main.tf @@ -0,0 +1,8 @@ +module "foo" { + source = "./foo" +} + +module "bar" { + source = "./bar" + in = "${module.foo.data}" +}