Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error planning tainted resource when it no longer exists #27563

Merged
merged 2 commits into from
Jan 21, 2021

Conversation

jbardin
Copy link
Member

@jbardin jbardin commented Jan 21, 2021

When a resource returns an error during apply we "taint" the state for that resource, but save it just in case.
The resource would then be removed during the next refresh if it did not exist, and the plan should result in a Create action rather than a replacement. The tainted state however was compared against cty.NilVal rather than checking if it was more generally Null, which is the normal case after the resource is removed from the state.

Fixes #27559

Manual 0.14 backport will be required due to changes in 0.15

The existing context test files are becoming quite unwieldy.
Start new ones both to make editing easier, and to help discourage the
copy+pasting of older test patterns we no longer need.
@jbardin jbardin requested a review from a team January 21, 2021 18:01
@codecov
Copy link

codecov bot commented Jan 21, 2021

Codecov Report

Merging #27563 (cb7a08c) into master (08560ee) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted Files Coverage Δ
terraform/node_resource_abstract_instance.go 73.09% <100.00%> (ø)
terraform/node_resource_plan_instance.go 70.12% <100.00%> (+0.39%) ⬆️
communicator/communicator.go 77.19% <0.00%> (-3.51%) ⬇️
dag/walk.go 92.25% <0.00%> (+0.70%) ⬆️
dag/marshal.go 63.49% <0.00%> (+1.58%) ⬆️

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.
@jbardin jbardin force-pushed the jbardin/refresh-tainted branch from 009bdb6 to cb7a08c Compare January 21, 2021 18:32
Copy link
Contributor

@alisdair alisdair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me!

diags = diags.Append(refreshDiags)
if diags.HasErrors() {
return diags
}
instanceRefreshState = s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the temporary variable s needed here? I don't see the logical difference between this and the prior code, given the shortcut return on error.

Copy link
Member Author

@jbardin jbardin Jan 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instanceRefreshState is passed to plan below, but instanceRefreshState here is scoped only to this block and shadows the outer variable. The temporary value ensures both that we don't shadow the outer variable, and that the new value is re-assigned. (I could have just as easily declared a temp diagnostics variable and removed the :=)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see now, thanks for clarifying!

@ghost
Copy link

ghost commented Feb 21, 2021

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked as resolved and limited conversation to collaborators Feb 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

invalid planned change after resouce creation failure
2 participants