terraform: don't prune if there are known tainted resources
This commit is contained in:
parent
8d2ed22e97
commit
9c14315336
|
@ -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{},
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue