From c706c8f92b4867a144f735ef821811ac40b374b8 Mon Sep 17 00:00:00 2001 From: Barrett Clark Date: Wed, 1 Dec 2021 10:22:05 -0600 Subject: [PATCH] Do not ask to migrate empty default workspace When migrating from an explicit local backend to Terraform Cloud, we ask if you want to migrate the state. If there is no state to migrate we should not ask if they want to migrate the emptiness. --- internal/command/meta_backend_migrate.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/internal/command/meta_backend_migrate.go b/internal/command/meta_backend_migrate.go index 5b476ff2b..8cd011eff 100644 --- a/internal/command/meta_backend_migrate.go +++ b/internal/command/meta_backend_migrate.go @@ -579,6 +579,21 @@ func (m *Meta) backendMigrateTFC(opts *backendMigrateOpts) error { opts.sourceWorkspace = currentWorkspace log.Printf("[INFO] backendMigrateTFC: single-to-single migration from source %s to destination %q", opts.sourceWorkspace, opts.destinationWorkspace) + + // If the current workspace is has no state we do not need to ask + // if they want to migrate the state. + sourceState, err := opts.Source.StateMgr(currentWorkspace) + if err != nil { + return err + } + if err := sourceState.RefreshState(); err != nil { + return err + } + if sourceState.State().Empty() { + log.Printf("[INFO] backendMigrateTFC: skipping migration because source %s is empty", opts.sourceWorkspace) + return nil + } + // Run normal single-to-single state migration. // This will handle both situations where the new cloud backend // configuration is using a workspace.name strategy or workspace.tags