terraform: set the diff up properly with tainted resources

This commit is contained in:
Mitchell Hashimoto 2015-02-12 13:10:21 -08:00
parent e82affdf5c
commit ef32656a65
3 changed files with 48 additions and 1 deletions

View File

@ -1177,7 +1177,6 @@ func TestContext2Plan_state(t *testing.T) {
}
}
/*
func TestContext2Plan_taint(t *testing.T) {
m := testModule(t, "plan-taint")
p := testProvider("aws")

View File

@ -184,6 +184,50 @@ func (n *EvalDiffDestroyModule) Type() EvalType {
return EvalTypeNull
}
// EvalDiffTainted is an EvalNode implementation that writes the diff to
// the full diff.
type EvalDiffTainted struct {
Name string
Diff *InstanceDiff
}
func (n *EvalDiffTainted) Args() ([]EvalNode, []EvalType) {
return nil, nil
}
// TODO: test
func (n *EvalDiffTainted) Eval(
ctx EvalContext, args []interface{}) (interface{}, error) {
state, lock := ctx.State()
// Get a read lock so we can access this instance
lock.RLock()
defer lock.RUnlock()
// Look for the module state. If we don't have one, then it doesn't matter.
mod := state.ModuleByPath(ctx.Path())
if mod == nil {
return nil, nil
}
// Look for the resource state. If we don't have one, then it is okay.
rs := mod.Resources[n.Name]
if rs == nil {
return nil, nil
}
// If we have tainted, then mark it on the diff
if len(rs.Tainted) > 0 {
n.Diff.DestroyTainted = true
}
return nil, nil
}
func (n *EvalDiffTainted) Type() EvalType {
return EvalTypeNull
}
// EvalWriteDiff is an EvalNode implementation that writes the diff to
// the full diff.
type EvalWriteDiff struct {

View File

@ -175,6 +175,10 @@ func (n *graphNodeExpandedResource) EvalTree() EvalNode {
Output: &diff,
},
},
&EvalDiffTainted{
Diff: &diff,
Name: n.stateId(),
},
&EvalWriteDiff{
Name: n.stateId(),
Diff: &diff,