fix null check and shadowed state variable

The tainted state was checked against `cty.NilVal`, however it was
always being set to a null value.

The refreshed state value was being shadowed, and not used in the
following plan.
This commit is contained in:
James Bardin 2021-01-21 12:46:37 -05:00
parent e4e50617aa
commit cb7a08c691
2 changed files with 3 additions and 2 deletions

View File

@ -905,7 +905,7 @@ func (n *NodeAbstractResourceInstance) plan(
// If our prior value was tainted then we actually want this to appear
// as a replace change, even though so far we've been treating it as a
// create.
if action == plans.Create && priorValTainted != cty.NilVal {
if action == plans.Create && !priorValTainted.IsNull() {
if createBeforeDestroy {
action = plans.CreateThenDelete
} else {

View File

@ -128,11 +128,12 @@ func (n *NodePlannableResourceInstance) managedResourceExecute(ctx EvalContext)
// Refresh, maybe
if !n.skipRefresh {
instanceRefreshState, refreshDiags := n.refresh(ctx, instanceRefreshState)
s, refreshDiags := n.refresh(ctx, instanceRefreshState)
diags = diags.Append(refreshDiags)
if diags.HasErrors() {
return diags
}
instanceRefreshState = s
diags = diags.Append(n.writeResourceInstanceState(ctx, instanceRefreshState, n.Dependencies, refreshState))
if diags.HasErrors() {