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

Use saved plan to determine CreateBeforeDestroy status #26192

Merged
merged 3 commits into from
Sep 14, 2020
Merged

Conversation

jbardin
Copy link
Member

@jbardin jbardin commented Sep 9, 2020

If the planed action changes from CreateThenDelete to DeleteThenCreate,
terraform will present an error like:

Error: Provider produced inconsistent final plan

When expanding the plan for null_resource.a to include new values learned so
far during apply, provider "registry.terraform.io/hashicorp/null" changed the
planned action from CreateThenDelete to DeleteThenCreate.

This is a bug in the provider, which should be reported in the provider's own
issue tracker.

This was being reported to providers as the message indicated, so wasn't
immediately visible to core developers, e.g.

hashicorp/terraform-provider-aws#15044
hashicorp/terraform-provider-aws#15048
https://discuss.hashicorp.com/t/this-is-a-bug-in-the-provider-which-should-be-reported-in-the-providers-own-issue-tracker/13190
hashicorp/terraform-provider-aws#13823 (comment)
hashicorp/terraform-provider-aws#10297 (comment)

Since the provider does not influence the status of CreateBeforeDestroy,
we first fix the output to indicate that this is a bug in terraform.

In order to prevent the error, we need to check for a saved plan with a
CreateThenDelete action and rely on that to determine the status of
CreateBeforeDestroy. Due to the eval-node pattern currently in use,
this needs to be maintained in both the apply node and the eval nodes.
Future refactoring can work on unifying these codepaths, and making
these internal flags less fragile.

Fixes #26180

A provider cannot influence CreateThenDelete vs DeleteThenCreate, so we
shouldn't attribute this to the provider in the error.
If a resource is forced CreateBeforeDestroy from a dependent resource,
and that dependent has no changes, the plan is changed from
CreateThenDelete to DeleteThenCreate causing an apply error.
When applying a plan, a forced CreateBeforeDestroy may not be set during
the apply walk when downstream resources are no longer present in the
graph. We still need to stick to that plan, and both the
NodeApplyableResourceInstance EvalTree and the individual Eval nodes
need to operate on that planned value.

Ensure that we always check for an existing plan when determining
CreateBeforeDestroy status. This must happen in 2 different code paths
due to the eval node pattern currently in-use. Future refactoring may be
able to unify these code-paths to make this less fragile.
@jbardin jbardin requested review from mildwonkey and a team September 9, 2020 21:39
@codecov
Copy link

codecov bot commented Sep 9, 2020

Codecov Report

Merging #26192 into master will decrease coverage by 0.01%.
The diff coverage is 40.00%.

Impacted Files Coverage Δ
terraform/eval_diff.go 68.22% <35.71%> (-1.25%) ⬇️
terraform/node_resource_apply_instance.go 80.31% <100.00%> (+0.15%) ⬆️
internal/providercache/dir.go 70.68% <0.00%> (-5.18%) ⬇️
dag/marshal.go 53.33% <0.00%> (-1.12%) ⬇️

@jbardin jbardin merged commit 84438d3 into master Sep 14, 2020
@jbardin jbardin deleted the jbardin/lost-cbd branch September 14, 2020 12:47
@jbardin jbardin mentioned this pull request Sep 14, 2020
alanraison added a commit to alanraison/gitpod that referenced this pull request Oct 2, 2020
In order to take advantage of hashicorp/terraform#26192, update to the latest terraform version.
csweichel pushed a commit to gitpod-io/gitpod that referenced this pull request Oct 12, 2020
In order to take advantage of hashicorp/terraform#26192, update to the latest terraform version.
@ghost
Copy link

ghost commented Oct 15, 2020

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 Oct 15, 2020
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.

Incorrect "Provider produced inconsistent final plan" error, changing CreateThenDelete to DeleteThenCreate.
2 participants