diff --git a/terraform/graph.go b/terraform/graph.go index 61fb94ceab..c952bb4ee5 100644 --- a/terraform/graph.go +++ b/terraform/graph.go @@ -283,11 +283,26 @@ func graphAddDiff(g *depgraph.Graph, d *Diff) error { // Make the diff _just_ the destroy. newNode.Resource.Diff = &ResourceDiff{Destroy: true} - // Append it to the list so we handle it later + // Create the new node newN := &depgraph.Noun{ Name: fmt.Sprintf("%s (destroy)", newNode.Resource.Id), Meta: newNode, } + newN.Deps = make([]*depgraph.Dependency, 0, len(n.Deps)) + for _, d := range n.Deps { + // We don't want to copy any resource dependencies + if _, ok := d.Target.Meta.(*GraphNodeResource); ok { + continue + } + + newN.Deps = append(newN.Deps, &depgraph.Dependency{ + Name: d.Name, + Source: newN, + Target: d.Target, + }) + } + + // Append it to the list so we handle it later nlist = append(nlist, newN) // Mark the old diff to not destroy since we handle that in diff --git a/terraform/graph_test.go b/terraform/graph_test.go index 1b38be5115..b634b9cce4 100644 --- a/terraform/graph_test.go +++ b/terraform/graph_test.go @@ -277,11 +277,16 @@ root: root aws_instance.bar aws_instance.bar -> aws_instance.bar (destroy) aws_instance.bar -> aws_instance.foo + aws_instance.bar -> provider.aws aws_instance.bar (destroy) + aws_instance.bar (destroy) -> provider.aws aws_instance.foo aws_instance.foo -> aws_instance.foo (destroy) + aws_instance.foo -> provider.aws aws_instance.foo (destroy) aws_instance.foo (destroy) -> aws_instance.bar (destroy) + aws_instance.foo (destroy) -> provider.aws +provider.aws root root -> aws_instance.bar root -> aws_instance.foo diff --git a/terraform/test-fixtures/graph-diff-destroy/main.tf b/terraform/test-fixtures/graph-diff-destroy/main.tf index da9db4e0c8..acbc6dd33a 100644 --- a/terraform/test-fixtures/graph-diff-destroy/main.tf +++ b/terraform/test-fixtures/graph-diff-destroy/main.tf @@ -1,3 +1,5 @@ +provider "aws" {} + resource "aws_instance" "foo" { }