terraform: fix potential case where cycle is made

This commit is contained in:
Mitchell Hashimoto 2014-08-12 17:08:12 -07:00
parent acc9cf0003
commit 2e777d87a2
3 changed files with 21 additions and 0 deletions

View File

@ -1,6 +1,8 @@
package depgraph
import (
"fmt"
"github.com/hashicorp/terraform/digraph"
)
@ -31,6 +33,14 @@ func (d *Dependency) Tail() digraph.Node {
return d.Target
}
func (d *Dependency) GoString() string {
return fmt.Sprintf(
"*Dependency{Name: %s, Source: %s, Target: %s}",
d.Name,
d.Source.Name,
d.Target.Name)
}
func (d *Dependency) String() string {
return d.Name
}

View File

@ -1,6 +1,8 @@
package depgraph
import (
"fmt"
"github.com/hashicorp/terraform/digraph"
)
@ -22,6 +24,10 @@ func (n *Noun) Edges() []digraph.Edge {
return edges
}
func (n *Noun) GoString() string {
return fmt.Sprintf("*%#v", *n)
}
func (n *Noun) String() string {
return n.Name
}

View File

@ -376,6 +376,11 @@ func graphAddDiff(g *depgraph.Graph, d *Diff) error {
// dependencies. Look to see if they're managed.
for _, dep := range deps {
for _, n2 := range nlist {
// Don't ever depend on ourselves
if n2.Name == n.Name {
continue
}
rn2 := n2.Meta.(*GraphNodeResource)
if rn2.Resource.State.ID == dep.ID {
n2.Deps = append(n2.Deps, &depgraph.Dependency{