diff --git a/terraform/graph_builder.go b/terraform/graph_builder.go index aec167f93..0cdd76259 100644 --- a/terraform/graph_builder.go +++ b/terraform/graph_builder.go @@ -105,7 +105,7 @@ func (b *BuiltinGraphBuilder) Steps() []GraphTransformer { // Create the destruction nodes &DestroyTransformer{}, &CreateBeforeDestroyTransformer{}, - &PruneDestroyTransformer{Diff: b.Diff}, + //&PruneDestroyTransformer{Diff: b.Diff, State: b.State}, // Make sure we create one root &RootTransformer{}, diff --git a/terraform/transform_destroy.go b/terraform/transform_destroy.go index 44252bc60..a97246b5d 100644 --- a/terraform/transform_destroy.go +++ b/terraform/transform_destroy.go @@ -172,14 +172,19 @@ func (t *CreateBeforeDestroyTransformer) Transform(g *Graph) error { // PruneDestroyTransformer is a GraphTransformer that removes the destroy // nodes that aren't in the diff. type PruneDestroyTransformer struct { - Diff *Diff + Diff *Diff + State *State } func (t *PruneDestroyTransformer) Transform(g *Graph) error { var modDiff *ModuleDiff + var modState *ModuleState if t.Diff != nil { modDiff = t.Diff.ModuleByPath(g.Path) } + if t.State != nil { + modState = t.State.ModuleByPath(g.Path) + } for _, v := range g.Vertices() { // If it is not a destroyer, we don't care @@ -194,7 +199,10 @@ func (t *PruneDestroyTransformer) Transform(g *Graph) error { continue } + // Assume we're removing it remove := true + + // We don't remove it if we find it in the diff if modDiff != nil { for k, _ := range modDiff.Resources { if strings.HasPrefix(k, prefix) { @@ -204,6 +212,20 @@ func (t *PruneDestroyTransformer) Transform(g *Graph) error { } } + // We don't remove it if we find a tainted resource + if modState != nil { + for k, v := range modState.Resources { + if !strings.HasPrefix(k, prefix) { + continue + } + + if len(v.Tainted) > 0 { + remove = false + break + } + } + } + // Remove the node if we have to if remove { g.Remove(v)