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

remove the use of data source prior state from planning #30832

Merged
merged 3 commits into from Apr 14, 2022

Conversation

jbardin
Copy link
Member

@jbardin jbardin commented Apr 11, 2022

After data source handling was moved from a separate refresh phase into the planning phase, reading the existing state was only used for informational purposes. This had been reduced to reporting warnings when the provider returned an unexpected value to try and help locate legacy provider bugs, but any actual issues located from those warnings were very few and far between.

Because the prior state cannot be reliably decoded when faced with incompatible provider schema upgrades, and there is no longer any significant reason to try and get the prior state at all, we can skip the process entirely.

The only place where the prior state was functionally used was in the destroy path to create the change entry. Because a data source destroy is only for cleanup purposes to clean out the state using the same code paths as a managed resource, we can substitute the prior state in the change with a null value to maintain the same behavior.

This is a more complete followup to #30830, not intended for backport.

After data source handling was moved from a separate refresh phase into
the planning phase, reading the existing state was only used for
informational purposes. This had been reduced to reporting warnings when
the provider returned an unexpected value to try and help locate legacy
provider bugs, but any actual issues located from those warnings were
very few and far between.

Because the prior state cannot be reliably decoded when faced with
incompatible provider schema upgrades, and there is no longer any
significant reason to try and get the prior state at all, we can skip
the process entirely.
Data sources should not require reading the previous versions. While we
previously skipped the decoding if it were to fail, this removes the
need for any prior state at all.

The only place where the prior state was functionally used was in the
destroy path. Because a data source destroy is only for cleanup purposes
to clean out the state using the same code paths as a managed resource,
we can substitute the prior state in the change change with a null value
to maintain the same behavior.
@jbardin jbardin requested a review from a team April 11, 2022 16:02
@vercel
Copy link

vercel bot commented Apr 11, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/hashicorp/terraform/E2RYCnftpwH4WghxQVLhJjfSMt7P
✅ Preview: https://terraform-git-jbardin-data-readresourceinstancestate-hashicorp.vercel.app

@jbardin jbardin changed the title Jbardin/data read resource instance state remove the use of data source prior state from planning Apr 11, 2022
@@ -1515,9 +1512,6 @@ func (n *NodeAbstractResourceInstance) planDataSource(ctx EvalContext, currentSt
)
diags = diags.Append(checkDiags)
if diags.HasErrors() {
diags = diags.Append(ctx.Hook(func(h Hook) (HookAction, error) {
return h.PostApply(n.Addr, states.CurrentGen, priorVal, diags.Err())
}))
Copy link
Member

Choose a reason for hiding this comment

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

I was a bit worried here that we'd break the timer-based "Still reading…" UI hooks here by sometimes calling PreApply without a corresponding PostApply, but after trying to trace through the code to see if that's possible I'm completely lost 😵‍💫 Just raising it in case you hadn't considered it and think it's worth looking into.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! I could not find where this was used at all, and wasn't surprised since most of the hooks are no longer used. I didn't think about the "Still reading..." output though, so I'll walk back from there once to doublecheck before merging.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, this is not even the correct place to call PostApply, since this section has nothing to do with reading the data source. The PostApply hook is still called after ReadDataSource, which corresponds to the ui output.

Base automatically changed from jbardin/data-schema-change to main April 14, 2022 13:47
@jbardin jbardin merged commit d360a78 into main Apr 14, 2022
@jbardin jbardin deleted the jbardin/data-readResourceInstanceState branch April 14, 2022 13:47
@github-actions
Copy link

Reminder for the merging maintainer: if this is a user-visible change, please update the changelog on the appropriate release branch.

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 15, 2022
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.

None yet

2 participants