terraform: copy the proper dependencies over on destroy plan

This commit is contained in:
Mitchell Hashimoto 2014-07-07 15:43:32 -07:00
parent 55eb06929e
commit 9f56fc8ddc
3 changed files with 23 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -1,3 +1,5 @@
provider "aws" {}
resource "aws_instance" "foo" {
}