Fix remote backend multi workspace state migration#28864
Conversation
When migrating multiple local workspaces to a remote backend target using the `prefix` argument, we need to perform the version check against all existing workspaces returned by the `Workspaces` method. Failing to do so will result in a version check error.
When performing state migration to a remote backend target, Terraform may fail due to mismatched remote and local Terraform versions. Here we add the `-ignore-remote-version` flag to allow users to ignore this version check when necessary.
There was a problem hiding this comment.
My manual testing looks good! I'm going to list my test steps here just because this was a slightly convoluted repro and I want to confirm that I didn't miss anything.
Multiple workspaces
- created local workspaces
oneandtwo - ran
terraform applyfor each so they had state - created TFC workspaces
test-oneandtest-twowith Terraform versions set to 0.13.7 - added remote backend configuration that looked like:
backend "remote" {
organization = "my-org"
workspaces {
prefix = "test-"
}
}
- ran
terraform initand attempted to migrate state, which failed as expected due to the mismatched versions - ran
terraform init -ignore-remote-version, which succeeded and state was successfully migrated to the two TFC workspaces - verified the happy path (that is, state migration with the prefix option works out of the box when the local and remote versions are compatible)
Single workspace
- double-checked that there's no regression when migrating state using the
nameoption to configure a single workspace
| } | ||
|
|
||
| _, err = opts.Two.Workspaces() | ||
| twoWorkspaces, err := opts.Two.Workspaces() |
There was a problem hiding this comment.
A very small naming nit: I was momentarily confused by this variable name because my brain tried to parse two as the number of workspaces 😆 would it be weird to call this backendTwoWorkspaces instead? I realize that breaks with the naming convention of the other variables in this file, though.
There was a problem hiding this comment.
I agree that this variable naming is confusing, but as you noted the rest of the function (and the entire file) has this pattern established, and I don't want to change everything else so I intend to leave it as-is 😑
|
Thank you for the very thorough manual testing, @radditude! 🙌 |
|
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. |
Two changes, both addressing the same underlying issue:
Fix faulty state migration version check when using multiple workspaces
When migrating multiple local workspaces to a remote backend target using the
prefixargument, we need to perform the version check against all existing workspaces returned by theWorkspacesmethod. Failing to do so will result in a version check error.Add
-ignore-remote-versionflag for init as a fallbackWhen performing state migration to a remote backend target, Terraform may fail due to mismatched remote and local Terraform versions. Here we add the
-ignore-remote-versionflag to allow users to ignore this version check when necessary.Unfortunately neither of these are easily unit tested. I've manually verified that this fixes #28858 when testing against my reproduction.