Skip to content
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/remote: Fix version check when migrating #29793

Merged
merged 1 commit into from
Oct 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions internal/command/meta_backend_migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,26 @@ func (m *Meta) backendMigrateState(opts *backendMigrateOpts) error {
// as we are migrating away and will not break a remote workspace.
m.ignoreRemoteBackendVersionConflict(opts.Source)

for _, workspace := range destinationWorkspaces {
// Disregard remote Terraform version if instructed to do so via CLI flag.
if m.ignoreRemoteVersion {
m.ignoreRemoteBackendVersionConflict(opts.Destination)
} else {
// 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.Destination, workspace)
if diags.HasErrors() {
return diags.Err()
for _, workspace := range destinationWorkspaces {
diags := m.remoteBackendVersionCheck(opts.Destination, workspace)
if diags.HasErrors() {
return diags.Err()
}
}
// If there are no specified destination workspaces, perform a remote
// backend version check with the default workspace.
if len(destinationWorkspaces) == 0 {
diags := m.remoteBackendVersionCheck(opts.Destination, backend.DefaultStateName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took me far too long to follow the chain to verify this does the right thing with the default workspace. 😅

if diags.HasErrors() {
return diags.Err()
}
}
}

Expand Down