From a9eb62d6922cfe6533bac15291f2ac246762ba2d Mon Sep 17 00:00:00 2001 From: Barrett Clark Date: Tue, 2 Nov 2021 15:53:26 -0500 Subject: [PATCH] Cloud: Migrate empty default workspace prompt Given: You have multiple explicit local workspaces, and the `default` workspace is empty. When: You migrate the workspaces to Terraform Cloud. Then: Terraform should _not_ ask for a workspace to migrate the `default` workspace to in Terraform Cloud. --- internal/command/meta_backend_migrate.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/internal/command/meta_backend_migrate.go b/internal/command/meta_backend_migrate.go index 97162eb8b..56faa4523 100644 --- a/internal/command/meta_backend_migrate.go +++ b/internal/command/meta_backend_migrate.go @@ -629,11 +629,25 @@ func (m *Meta) backendMigrateState_S_TFC(opts *backendMigrateOpts, sourceWorkspa defaultNewName := map[string]string{} for i := 0; i < len(sourceWorkspaces); i++ { if sourceWorkspaces[i] == backend.DefaultStateName { - newName, err := m.promptNewWorkspaceName(opts.DestinationType) + // For the default workspace we want to look to see if there is any state + // before we ask for a workspace name to migrate the default workspace into. + sourceState, err := opts.Source.StateMgr(backend.DefaultStateName) if err != nil { - return err + return fmt.Errorf(strings.TrimSpace( + errMigrateSingleLoadDefault), opts.SourceType, err) + } + // RefreshState is what actually pulls the state to be evaluated. + if err := sourceState.RefreshState(); err != nil { + return fmt.Errorf(strings.TrimSpace( + errMigrateSingleLoadDefault), opts.SourceType, err) + } + if !sourceState.State().Empty() { + newName, err := m.promptNewWorkspaceName(opts.DestinationType) + if err != nil { + return err + } + defaultNewName[sourceWorkspaces[i]] = newName } - defaultNewName[sourceWorkspaces[i]] = newName } }