Backport of backend: Validate remote backend Terraform version into v0.12 #27002
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport
This PR is a manual backport of #26947 targeted at the 0.12 branch for future release, likely in 0.12.30.
The below text is copied from the body of the original PR.
When using the enhanced remote backend, a subset of all Terraform operations are supported. Of these, only plan and apply can be executed on the remote infrastructure (e.g. Terraform Cloud). Other operations run locally and use the remote backend for state storage.
This causes problems when the local version of Terraform does not match the configured version from the remote workspace. If the two versions are incompatible, an
import
orstate mv
operation can cause the remote workspace to be unusable until a manual fix is applied.To prevent this from happening accidentally, this commit introduces a check that the local Terraform version and the configured remote workspace Terraform version are compatible. This check is skipped for commands which do not write state, and can also be disabled by the use of a new command-line flag,
-ignore-remote-version
.Terraform version compatibility is defined as:
If the two versions are incompatible, a diagnostic is displayed, advising that the error can be suppressed with
-ignore-remote-version
. When this flag is used, the diagnostic is still displayed, but as a warning instead of an error.Commands which will not write state can assert this fact by calling the helper
meta.ignoreRemoteBackendVersionConflict
, which will disable the checks. Those which can write state should instead call the helpermeta.remoteBackendVersionCheck
, which will return diagnostics for display.In addition to these explicit paths for managing the version check, we have an implicit check in the remote backend's state manager initialization method. Both of the above helpers will disable this check. This fallback is in place to ensure that future code paths which access state cannot accidentally skip the remote version check.
Release plans
This change is intended to ship with 0.15.0, and we also intend to backport to earlier release series. The current plan is 0.14, 0.13, and 0.12.
Screenshot
Here's a session which demonstrates both the error and warning forms of the diagnostics: