terraform: clean up root deps on the graph

This commit is contained in:
Mitchell Hashimoto 2014-07-03 20:51:31 -07:00
parent e7b7644cbf
commit ba144ef933
2 changed files with 18 additions and 3 deletions

View File

@ -168,16 +168,19 @@ func graphAddConfigResources(
resourceNouns := make([]*depgraph.Noun, r.Count) resourceNouns := make([]*depgraph.Noun, r.Count)
for i := 0; i < r.Count; i++ { for i := 0; i < r.Count; i++ {
name := r.Id() name := r.Id()
index := -1
// If we have a count that is more than one, then make sure // If we have a count that is more than one, then make sure
// we suffix with the number of the resource that this is. // we suffix with the number of the resource that this is.
if r.Count > 1 { if r.Count > 1 {
name = fmt.Sprintf("%s.%d", name, i) name = fmt.Sprintf("%s.%d", name, i)
index = i
} }
resourceNouns[i] = &depgraph.Noun{ resourceNouns[i] = &depgraph.Noun{
Name: name, Name: name,
Meta: &GraphNodeResource{ Meta: &GraphNodeResource{
Index: index,
Type: r.Type, Type: r.Type,
Config: r, Config: r,
Resource: &Resource{ Resource: &Resource{
@ -391,6 +394,7 @@ func graphAddOrphans(g *depgraph.Graph, c *config.Config, s *State) {
noun := &depgraph.Noun{ noun := &depgraph.Noun{
Name: k, Name: k,
Meta: &GraphNodeResource{ Meta: &GraphNodeResource{
Index: -1,
Type: rs.Type, Type: rs.Type,
Orphan: true, Orphan: true,
Resource: &Resource{ Resource: &Resource{
@ -456,6 +460,20 @@ func graphAddProviderConfigs(g *depgraph.Graph, c *config.Config) {
func graphAddRoot(g *depgraph.Graph) { func graphAddRoot(g *depgraph.Graph) {
root := &depgraph.Noun{Name: GraphRootNode} root := &depgraph.Noun{Name: GraphRootNode}
for _, n := range g.Nouns { 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{ root.Deps = append(root.Deps, &depgraph.Dependency{
Name: n.Name, Name: n.Name,
Source: root, Source: root,

View File

@ -254,9 +254,6 @@ aws_load_balancer.weblb
aws_load_balancer.weblb -> aws_instance.web aws_load_balancer.weblb -> aws_instance.web
root root
root -> aws_instance.web root -> aws_instance.web
root -> aws_instance.web.0
root -> aws_instance.web.1
root -> aws_instance.web.2
root -> aws_load_balancer.weblb root -> aws_load_balancer.weblb
` `