terraform: fix dot output for meta resources

This commit is contained in:
Armon Dadgar 2014-07-24 18:56:05 -04:00
parent 11b4ebea9a
commit 0da10b813b
1 changed files with 44 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"github.com/hashicorp/terraform/depgraph" "github.com/hashicorp/terraform/depgraph"
"github.com/hashicorp/terraform/digraph"
) )
// GraphDot returns the dot formatting of a visual representation of // GraphDot returns the dot formatting of a visual representation of
@ -141,6 +142,49 @@ func graphDotAddResources(buf *bytes.Buffer, g *depgraph.Graph) {
buf.WriteString(edgeBuf.String()) buf.WriteString(edgeBuf.String())
buf.WriteString("\n") buf.WriteString("\n")
} }
// Handle the meta resources
edgeBuf.Reset()
for _, n := range g.Nouns {
_, ok := n.Meta.(*GraphNodeResourceMeta)
if !ok {
continue
}
// Determine which edges to add
var edges []digraph.Edge
if hasDiff {
for _, e := range n.Edges() {
rn, ok := e.Tail().(*depgraph.Noun).Meta.(*GraphNodeResource)
if !ok {
continue
}
if rn.Resource.Diff == nil || rn.Resource.Diff.Empty() {
continue
}
edges = append(edges, e)
}
} else {
edges = n.Edges()
}
// Do not draw if we have no edges
if len(edges) == 0 {
continue
}
for _, e := range edges {
target := e.Tail()
edgeBuf.WriteString(fmt.Sprintf(
"\t\"%s\" -> \"%s\";\n",
n,
target))
}
}
if edgeBuf.Len() > 0 {
buf.WriteString(edgeBuf.String())
buf.WriteString("\n")
}
} }
func graphDotAddResourceProviders(buf *bytes.Buffer, g *depgraph.Graph) { func graphDotAddResourceProviders(buf *bytes.Buffer, g *depgraph.Graph) {