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

builtin/providers/terraform: Disable remote state file version checks #27011

Merged

Conversation

alisdair
Copy link
Contributor

Backport of #26692 to v0.12. This was not a clean cherry-pick, so I've pushed each commit individually to show passing tests. From the original PR description:


The builtin Terraform provider's remote state data source uses a configured backend to fetch a given state, in order to allow access to its root module outputs. Until this change, this was only possible with remote states which are from the current Terraform version or older, forcing multi-state users to carefully orchestrate Terraform upgrades.

We can now disable this version check, and allow any Terraform state file that the current Terraform version can parse. Since we are only ever accessing root module outputs, this is very likely to be safe for the foreseeable future.

Notes to reviewers 📝

I believe this PR will be easier to review one commit at a time. There is some detail in each commit message which may be worth reading. Each commit except the last one should be a no-op, and existing tests pass.

This specific implementation of this idea was intended to be as mechanically simple as possible, because it covers so many files which are difficult to test. The ambition is for reviewers to be confident enough in this change to approve back-porting it to earlier Terraform versions.

Instead of always checking the Terraform version associated with a state
file when reading it, we add a CheckTerraformVersion method and call it
from locations where we care about enforcing this check.

For this commit, the check has been retained at all call sites for
states/statefile.Read, with these exceptions:

- Unit tests, which shouldn't care about the state file version;
- E2E test runner which should always be using valid state files;
- terraform.ShimLegacyState, where the check is pointless as the state
  file was just created by the current Terraform version.
Add RefreshStateWithoutCheckVersion method to the statemgr.Persistent
interface, allowing callers to refresh state from the backend without
raising errors if the state's Terraform version is thought to be
not fully compatible.

This enables use cases where we can be extremely confident that any
state file we can read is suitable, such as the Terraform provider's
remote state data source, which only reads outputs.
Allow users of backends to initialize a state manager instance without
checking the Terraform version of any state files which are retrieved
during this process. Many backends call RefreshState as part of
initialization, and this new method instead calls the new
RefreshStateWithoutCheckVersion method to prevent version checking.
The builtin Terraform provider's remote state data source uses a
configured backend to fetch a given state, in order to allow access to
its root module outputs. Until this commit, this was only possible
with remote states which are from the current Terraform version or
older, forcing multi-state users to carefully orchestrate Terraform
upgrades.

Building on previous commits in this branch, we now disable this version
check, and allow any Terraform state file that the current Terraform
version can parse. Since we are only ever accessing root module outputs,
this is very likely to be safe for the foreseeable future.
@alisdair alisdair requested a review from a team November 23, 2020 15:50
@codecov
Copy link

codecov bot commented Nov 23, 2020

Codecov Report

Merging #27011 (08f25fa) into v0.12 (c5c0268) will decrease coverage by 1.34%.
The diff coverage is 8.39%.

Impacted Files Coverage Δ
backend/atlas/backend.go 55.55% <0.00%> (-1.59%) ⬇️
backend/backend.go 0.00% <ø> (ø)
backend/local/backend.go 46.29% <0.00%> (-1.78%) ⬇️
backend/nil.go 0.00% <0.00%> (ø)
backend/remote-state/artifactory/backend.go 91.80% <0.00%> (+0.89%) ⬆️
backend/remote-state/azure/backend_state.go 0.00% <0.00%> (ø)
backend/remote-state/cos/backend_state.go 4.93% <0.00%> (-2.47%) ⬇️
backend/remote-state/etcdv2/backend.go 0.00% <0.00%> (ø)
backend/remote-state/etcdv3/backend_state.go 0.00% <0.00%> (ø)
backend/remote-state/gcs/backend_state.go 7.79% <0.00%> (-2.34%) ⬇️
... and 673 more

@alisdair alisdair self-assigned this Nov 23, 2020
Copy link
Contributor

@pselle pselle left a comment

Choose a reason for hiding this comment

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

As usual, I really appreciate the attention and detail you put into your commit text/summaries that made walking through this PR commit-by-commit indeed easier to read (and thanks for giving that recommendation!). Thank you for the effort you put in there, it always inspires me to boost the quality of my own!

@alisdair alisdair merged commit bcb68ac into v0.12 Dec 8, 2020
@alisdair alisdair deleted the alisdair/builtin-terraform-provider-disable-version-checks-012 branch December 8, 2020 15:06
@ghost
Copy link

ghost commented Jan 8, 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 Jan 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants