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:
parent
19313980b7
commit
6692336541
|
@ -57,7 +57,7 @@ func (m *Meta) backendMigrateState(opts *backendMigrateOpts) error {
|
||||||
errMigrateLoadStates), opts.OneType, err)
|
errMigrateLoadStates), opts.OneType, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = opts.Two.Workspaces()
|
twoWorkspaces, err := opts.Two.Workspaces()
|
||||||
if err == backend.ErrWorkspacesNotSupported {
|
if err == backend.ErrWorkspacesNotSupported {
|
||||||
twoSingle = true
|
twoSingle = true
|
||||||
err = nil
|
err = nil
|
||||||
|
@ -77,12 +77,14 @@ func (m *Meta) backendMigrateState(opts *backendMigrateOpts) error {
|
||||||
// as we are migrating away and will not break a remote workspace.
|
// as we are migrating away and will not break a remote workspace.
|
||||||
m.ignoreRemoteBackendVersionConflict(opts.One)
|
m.ignoreRemoteBackendVersionConflict(opts.One)
|
||||||
|
|
||||||
// Check the remote Terraform version for the state destination backend. If
|
for _, twoWorkspace := range twoWorkspaces {
|
||||||
// it's a Terraform Cloud remote backend, we want to ensure that we don't
|
// Check the remote Terraform version for the state destination backend. If
|
||||||
// break the workspace by uploading an incompatible state file.
|
// it's a Terraform Cloud remote backend, we want to ensure that we don't
|
||||||
diags := m.remoteBackendVersionCheck(opts.Two, opts.twoEnv)
|
// break the workspace by uploading an incompatible state file.
|
||||||
if diags.HasErrors() {
|
diags := m.remoteBackendVersionCheck(opts.Two, twoWorkspace)
|
||||||
return diags.Err()
|
if diags.HasErrors() {
|
||||||
|
return diags.Err()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine migration behavior based on whether the source/destination
|
// Determine migration behavior based on whether the source/destination
|
||||||
|
|
Loading…
Reference in New Issue