terraform: fix cycle that could happen during destroy

This commit is contained in:
Mitchell Hashimoto 2014-07-07 15:37:50 -07:00
parent 1c725896ca
commit 55eb06929e
3 changed files with 5 additions and 3 deletions

View File

@ -284,12 +284,9 @@ func graphAddDiff(g *depgraph.Graph, d *Diff) error {
newNode.Resource.Diff = &ResourceDiff{Destroy: true} newNode.Resource.Diff = &ResourceDiff{Destroy: true}
// Append it to the list so we handle it later // Append it to the list so we handle it later
deps := make([]*depgraph.Dependency, len(n.Deps))
copy(deps, n.Deps)
newN := &depgraph.Noun{ newN := &depgraph.Noun{
Name: fmt.Sprintf("%s (destroy)", newNode.Resource.Id), Name: fmt.Sprintf("%s (destroy)", newNode.Resource.Id),
Meta: newNode, Meta: newNode,
Deps: deps,
} }
nlist = append(nlist, newN) nlist = append(nlist, newN)

View File

@ -276,6 +276,7 @@ const testTerraformGraphDiffDestroyStr = `
root: root root: root
aws_instance.bar aws_instance.bar
aws_instance.bar -> aws_instance.bar (destroy) aws_instance.bar -> aws_instance.bar (destroy)
aws_instance.bar -> aws_instance.foo
aws_instance.bar (destroy) aws_instance.bar (destroy)
aws_instance.foo aws_instance.foo
aws_instance.foo -> aws_instance.foo (destroy) aws_instance.foo -> aws_instance.foo (destroy)

View File

@ -1,2 +1,6 @@
resource "aws_instance" "foo" { resource "aws_instance" "foo" {
} }
resource "aws_instance" "bar" {
foo = "${aws_instance.foo.id}"
}