cloud: Automatically select renamed current workspace
After migrating to TFC with renamed workspaces, automatically select what was the previous current workspace on behalf of the user. We don't need to make the user reselect.
This commit is contained in:
parent
f80b2177c8
commit
c3bf5d4512
|
@ -613,6 +613,12 @@ func (m *Meta) backendMigrateTFC(opts *backendMigrateOpts) error {
|
||||||
func (m *Meta) backendMigrateState_S_TFC(opts *backendMigrateOpts, sourceWorkspaces []string) error {
|
func (m *Meta) backendMigrateState_S_TFC(opts *backendMigrateOpts, sourceWorkspaces []string) error {
|
||||||
log.Print("[TRACE] backendMigrateState: migrating all named workspaces")
|
log.Print("[TRACE] backendMigrateState: migrating all named workspaces")
|
||||||
|
|
||||||
|
currentWorkspace, err := m.Workspace()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
newCurrentWorkspace := ""
|
||||||
|
|
||||||
// This map is used later when doing the migration per source/destination.
|
// This map is used later when doing the migration per source/destination.
|
||||||
// If a source has 'default', then we ask what the new name should be.
|
// If a source has 'default', then we ask what the new name should be.
|
||||||
// And further down when we actually run state migration for each
|
// And further down when we actually run state migration for each
|
||||||
|
@ -653,15 +659,35 @@ func (m *Meta) backendMigrateState_S_TFC(opts *backendMigrateOpts, sourceWorkspa
|
||||||
return fmt.Errorf(strings.TrimSpace(
|
return fmt.Errorf(strings.TrimSpace(
|
||||||
errMigrateMulti), name, opts.SourceType, opts.DestinationType, err)
|
errMigrateMulti), name, opts.SourceType, opts.DestinationType, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if currentWorkspace == opts.sourceWorkspace {
|
||||||
|
newCurrentWorkspace = opts.destinationWorkspace
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// After migrating multiple workspaces, we want to ensure that a workspace is
|
// After migrating multiple workspaces, we need to reselect the current workspace as it may
|
||||||
// set or we prompt the user to set a workspace.
|
// have been renamed. Query the backend first to be sure it now exists, and if it does,
|
||||||
err = m.selectWorkspace(opts.Destination)
|
// select it.
|
||||||
|
workspaces, err := opts.Destination.Workspaces()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, name := range workspaces {
|
||||||
|
if name == newCurrentWorkspace {
|
||||||
|
if err = m.SetWorkspace(name); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we couldn't select the workspace automatically from the backend (maybe it was empty
|
||||||
|
// and wasn't migrated, for instance), ask the user to select one.
|
||||||
|
if err = m.selectWorkspace(opts.Destination); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue