From ef32656a656df8589ebb559f5810aa8aea169c71 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 12 Feb 2015 13:10:21 -0800 Subject: [PATCH] terraform: set the diff up properly with tainted resources --- terraform/context_test.go | 1 - terraform/eval_diff.go | 44 +++++++++++++++++++++++++++++++++ terraform/transform_resource.go | 4 +++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/terraform/context_test.go b/terraform/context_test.go index a9850fda1..f646e59a6 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -1177,7 +1177,6 @@ func TestContext2Plan_state(t *testing.T) { } } -/* func TestContext2Plan_taint(t *testing.T) { m := testModule(t, "plan-taint") p := testProvider("aws") diff --git a/terraform/eval_diff.go b/terraform/eval_diff.go index f2cd3590c..9a956fd40 100644 --- a/terraform/eval_diff.go +++ b/terraform/eval_diff.go @@ -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 { diff --git a/terraform/transform_resource.go b/terraform/transform_resource.go index a846cc47c..ed87bc868 100644 --- a/terraform/transform_resource.go +++ b/terraform/transform_resource.go @@ -175,6 +175,10 @@ func (n *graphNodeExpandedResource) EvalTree() EvalNode { Output: &diff, }, }, + &EvalDiffTainted{ + Diff: &diff, + Name: n.stateId(), + }, &EvalWriteDiff{ Name: n.stateId(), Diff: &diff,