From cf5f26bd9a33f07bbbcfbb1fb27ebaa528072460 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 9 Feb 2015 16:06:19 -0800 Subject: [PATCH] terraform: walk static subgraphs --- terraform/context_test.go | 42 +++++++++++++++++++-------------------- terraform/graph.go | 11 ++++++++++ 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/terraform/context_test.go b/terraform/context_test.go index 9ebe5766b..f89fda0cc 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -139,6 +139,27 @@ func TestContext2Validate_moduleGood(t *testing.T) { } } +func TestContext2Validate_moduleBadResource(t *testing.T) { + m := testModule(t, "validate-module-bad-rc") + p := testProvider("aws") + c := testContext2(t, &ContextOpts{ + Module: m, + Providers: map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + }) + + p.ValidateResourceReturnErrors = []error{fmt.Errorf("bad")} + + w, e := c.Validate() + if len(w) > 0 { + t.Fatalf("bad: %#v", w) + } + if len(e) == 0 { + t.Fatalf("bad: %#v", e) + } +} + func TestContext2Validate_orphans(t *testing.T) { p := testProvider("aws") m := testModule(t, "validate-good") @@ -480,27 +501,6 @@ func TestContext2Validate_varRefFilled(t *testing.T) { } /* -func TestContextValidate_moduleBadResource(t *testing.T) { - m := testModule(t, "validate-module-bad-rc") - p := testProvider("aws") - c := testContext(t, &ContextOpts{ - Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, - }) - - p.ValidateResourceReturnErrors = []error{fmt.Errorf("bad")} - - w, e := c.Validate() - if len(w) > 0 { - t.Fatalf("bad: %#v", w) - } - if len(e) == 0 { - t.Fatalf("bad: %#v", e) - } -} - func TestContextValidate_moduleProviderInherit(t *testing.T) { m := testModule(t, "validate-module-pc-inherit") p := testProvider("aws") diff --git a/terraform/graph.go b/terraform/graph.go index f8698c37e..cc5c5a6b2 100644 --- a/terraform/graph.go +++ b/terraform/graph.go @@ -173,6 +173,17 @@ func (g *Graph) walk(walker GraphWalker) error { } } + // If the node has a subgraph, then walk the subgraph + if sn, ok := v.(GraphNodeSubgraph); ok { + log.Printf( + "[DEBUG] vertex %s: walking subgraph", + dag.VertexName(v)) + + if rerr = sn.Subgraph().walk(walker); rerr != nil { + return + } + } + return nil }