From cbd64c0d3c25059c13f92bee0908f90b7d0c0874 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Thu, 7 Nov 2019 08:55:50 -0500 Subject: [PATCH] restore the prior tainted status on failed apply --- terraform/eval_apply.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/terraform/eval_apply.go b/terraform/eval_apply.go index 12ef46a48..215b9b657 100644 --- a/terraform/eval_apply.go +++ b/terraform/eval_apply.go @@ -253,6 +253,8 @@ func (n *EvalApply) Eval(ctx EvalContext) (interface{}, error) { } } + newStatus := states.ObjectReady + // Sometimes providers return a null value when an operation fails for some // reason, but we'd rather keep the prior state so that the error can be // corrected on a subsequent run. We must only do this for null new value @@ -265,12 +267,18 @@ func (n *EvalApply) Eval(ctx EvalContext) (interface{}, error) { // If change.Action is Create then change.Before will also be null, // which is fine. newVal = change.Before + + // If we're recovering the previous state, we also want to restore the + // the tainted status of the object. + if state.Status == states.ObjectTainted { + newStatus = states.ObjectTainted + } } var newState *states.ResourceInstanceObject if !newVal.IsNull() { // null value indicates that the object is deleted, so we won't set a new state in that case newState = &states.ResourceInstanceObject{ - Status: states.ObjectReady, + Status: newStatus, Value: newVal, Private: resp.Private, }