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.
This commit is contained in:
Barrett Clark 2021-11-02 15:53:26 -05:00
parent db9109d2ce
commit a9eb62d692
1 changed files with 17 additions and 3 deletions

View File

@ -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
}
}