cli: Fix state migration version check

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.
This commit is contained in:
Alisdair McDiarmid 2021-06-02 15:23:56 -04:00
parent 19313980b7
commit 6692336541
1 changed files with 9 additions and 7 deletions

View File

@ -57,7 +57,7 @@ func (m *Meta) backendMigrateState(opts *backendMigrateOpts) error {
errMigrateLoadStates), opts.OneType, err)
}
_, err = opts.Two.Workspaces()
twoWorkspaces, err := opts.Two.Workspaces()
if err == backend.ErrWorkspacesNotSupported {
twoSingle = true
err = nil
@ -77,13 +77,15 @@ func (m *Meta) backendMigrateState(opts *backendMigrateOpts) error {
// as we are migrating away and will not break a remote workspace.
m.ignoreRemoteBackendVersionConflict(opts.One)
for _, twoWorkspace := range twoWorkspaces {
// Check the remote Terraform version for the state destination backend. If
// it's a Terraform Cloud remote backend, we want to ensure that we don't
// break the workspace by uploading an incompatible state file.
diags := m.remoteBackendVersionCheck(opts.Two, opts.twoEnv)
diags := m.remoteBackendVersionCheck(opts.Two, twoWorkspace)
if diags.HasErrors() {
return diags.Err()
}
}
// Determine migration behavior based on whether the source/destination
// supports multi-state.