-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
backend: Validate remote backend Terraform version #26947
backend: Validate remote backend Terraform version #26947
Conversation
Codecov Report
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a good compromise! Thanks for working on this.
It does seem a little unfortunate that we had to add new CLI argument surface area to so many commands only for this one backend, but I don't have a better idea and it is at least consistent with our sense that the local vs. remote distinction will probably eventually become a first-class thing separate from what we otherwise think of as "backends" (state storage options for local operations).
One cosmetic feedback inline, but it's subjective so feel free to ignore it if you disagree with it.
Seems like GitHub helpfully lost my inline feedback. Thanks. 🙄 The gist of it was a couple ideas for the error messages:
|
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` or `state 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: - For all releases before 0.14.0, local must exactly equal remote, as two different versions cannot share state; - 0.14.0 to 1.0.x are compatible, as we will not change the state version number until at least Terraform 1.1.0; - Versions after 1.1.0 must have the same major and minor versions, as we will not change the state version number in a patch release. 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 helper `meta.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.
60e8173
to
c5c1f31
Compare
Thanks for the suggestions! I revised the diagnostic and I think it's clearer. Example:
|
This change broke our pipelines.. We use terraform_remote_state with backend set to remote and Terraform Cloud as the backend for all our workspaces. However, in all the workspaces we have Execution Mode set to local only and not remote. However, With the introduction of this change, we're required to changes the Execution Mode to remote and update the terraform version inline with the version required in the current workspace. Can't the terraform_remote_state verify the version of the remote state via the terraform_version in the state file instead? |
@e-moshaya Sorry about that! The behaviour you're seeing was unintentional, and the intended behaviour is as you proposed. See #27197 for a pending fix, which I hope to release today. |
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. |
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: