From 7c3e355bb0c15bcae19d26ca7545f520a74c91f7 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 7 May 2015 13:08:59 -0700 Subject: [PATCH] terraform: flattening multi-level modules works --- terraform/graph_builder_test.go | 32 +++++++++++++++++++ .../foo/bar/main.tf | 2 ++ .../foo/main.tf | 6 ++++ .../graph-builder-multi-level-module/main.tf | 4 +++ terraform/transform_flatten.go | 4 +++ 5 files changed, 48 insertions(+) create mode 100644 terraform/test-fixtures/graph-builder-multi-level-module/foo/bar/main.tf create mode 100644 terraform/test-fixtures/graph-builder-multi-level-module/foo/main.tf create mode 100644 terraform/test-fixtures/graph-builder-multi-level-module/main.tf diff --git a/terraform/graph_builder_test.go b/terraform/graph_builder_test.go index 0f66947fc..1f7f25055 100644 --- a/terraform/graph_builder_test.go +++ b/terraform/graph_builder_test.go @@ -136,6 +136,24 @@ func TestBuiltinGraphBuilder_cbdDepNonCbd_errorsWhenVerbose(t *testing.T) { } } +func TestBuiltinGraphBuilder_multiLevelModule(t *testing.T) { + b := &BuiltinGraphBuilder{ + Root: testModule(t, "graph-builder-multi-level-module"), + Validate: true, + } + + g, err := b.Build(RootModulePath) + if err != nil { + t.Fatalf("err: %s", err) + } + + actual := strings.TrimSpace(g.String()) + expected := strings.TrimSpace(testBuiltinGraphBuilderMultiLevelStr) + if actual != expected { + t.Fatalf("bad: %s", actual) + } +} + /* TODO: This exposes a really bad bug we need to fix after we merge the f-ast-branch. This bug still exists in master. @@ -213,3 +231,17 @@ module.consul (expanded) provider.aws provider.aws ` + +const testBuiltinGraphBuilderMultiLevelStr = ` +module.foo.module.bar.output.value + module.foo.module.bar.var.bar +module.foo.module.bar.plan-destroy +module.foo.module.bar.var.bar + module.foo.var.foo +module.foo.plan-destroy +module.foo.var.foo +root + module.foo.module.bar.output.value + module.foo.module.bar.plan-destroy + module.foo.plan-destroy +` diff --git a/terraform/test-fixtures/graph-builder-multi-level-module/foo/bar/main.tf b/terraform/test-fixtures/graph-builder-multi-level-module/foo/bar/main.tf new file mode 100644 index 000000000..6ee0b2889 --- /dev/null +++ b/terraform/test-fixtures/graph-builder-multi-level-module/foo/bar/main.tf @@ -0,0 +1,2 @@ +variable "bar" {} +output "value" { value = "${var.bar}" } diff --git a/terraform/test-fixtures/graph-builder-multi-level-module/foo/main.tf b/terraform/test-fixtures/graph-builder-multi-level-module/foo/main.tf new file mode 100644 index 000000000..dbe120fb4 --- /dev/null +++ b/terraform/test-fixtures/graph-builder-multi-level-module/foo/main.tf @@ -0,0 +1,6 @@ +module "bar" { + source = "./bar" + bar = "${var.foo}" +} + +variable "foo" {} diff --git a/terraform/test-fixtures/graph-builder-multi-level-module/main.tf b/terraform/test-fixtures/graph-builder-multi-level-module/main.tf new file mode 100644 index 000000000..3962c1d14 --- /dev/null +++ b/terraform/test-fixtures/graph-builder-multi-level-module/main.tf @@ -0,0 +1,4 @@ +module "foo" { + source = "./foo" + foo = "bar" +} diff --git a/terraform/transform_flatten.go b/terraform/transform_flatten.go index 4f9df8fb8..eb331ccef 100644 --- a/terraform/transform_flatten.go +++ b/terraform/transform_flatten.go @@ -53,6 +53,10 @@ func (t *FlattenTransformer) Transform(g *Graph) error { // Go through the subgraph and flatten all the nodes for _, sv := range subgraph.Vertices() { + if _, ok := sv.(GraphNodeSubPath); ok { + continue + } + fn, ok := sv.(GraphNodeFlattenable) if !ok { return fmt.Errorf(