From ba144ef93305a5e80a2b1f46d20e484adf29e519 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 3 Jul 2014 20:51:31 -0700 Subject: [PATCH] terraform: clean up root deps on the graph --- terraform/graph.go | 18 ++++++++++++++++++ terraform/graph_test.go | 3 --- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/terraform/graph.go b/terraform/graph.go index 01ef19cfc..8c7846a76 100644 --- a/terraform/graph.go +++ b/terraform/graph.go @@ -168,16 +168,19 @@ func graphAddConfigResources( resourceNouns := make([]*depgraph.Noun, r.Count) for i := 0; i < r.Count; i++ { name := r.Id() + index := -1 // If we have a count that is more than one, then make sure // we suffix with the number of the resource that this is. if r.Count > 1 { name = fmt.Sprintf("%s.%d", name, i) + index = i } resourceNouns[i] = &depgraph.Noun{ Name: name, Meta: &GraphNodeResource{ + Index: index, Type: r.Type, Config: r, Resource: &Resource{ @@ -391,6 +394,7 @@ func graphAddOrphans(g *depgraph.Graph, c *config.Config, s *State) { noun := &depgraph.Noun{ Name: k, Meta: &GraphNodeResource{ + Index: -1, Type: rs.Type, Orphan: true, Resource: &Resource{ @@ -456,6 +460,20 @@ func graphAddProviderConfigs(g *depgraph.Graph, c *config.Config) { func graphAddRoot(g *depgraph.Graph) { root := &depgraph.Noun{Name: GraphRootNode} for _, n := range g.Nouns { + switch m := n.Meta.(type) { + case *GraphNodeResource: + // If the resource is part of a group, we don't need to make a dep + if m.Index != -1 { + continue + } + case *GraphNodeResourceMeta: + // Always in the graph + case *GraphNodeResourceProvider: + // ResourceProviders don't need to be in the root deps because + // they're always pointed to by some resource. + continue + } + root.Deps = append(root.Deps, &depgraph.Dependency{ Name: n.Name, Source: root, diff --git a/terraform/graph_test.go b/terraform/graph_test.go index d395f0b35..f8d460e1c 100644 --- a/terraform/graph_test.go +++ b/terraform/graph_test.go @@ -254,9 +254,6 @@ aws_load_balancer.weblb aws_load_balancer.weblb -> aws_instance.web root root -> aws_instance.web - root -> aws_instance.web.0 - root -> aws_instance.web.1 - root -> aws_instance.web.2 root -> aws_load_balancer.weblb `