cloud: Add streamlined 'remote' backend state migration path

For Terraform Cloud users using the 'remote' backend, the existing
'pattern' prompt should work just fine - but because their workspaces
are already present in TFC, the 'migration' here is really just
realigning their local workspaces with Terraform Cloud. Instead of
forcing users to do the mental gymnastics of what it means to migrate
from 'prefix' - and because their remote workspaces probably already exist and
already conform to Terraform Cloud's naming concerns - streamline the
process for them and calculate the necessary pattern to migrate as-is,
without any user intervention necessary.
This commit is contained in:
Chris Arcand
2021-11-03 14:41:55 -05:00
parent 2690f738aa
commit 779c958fbf
3 changed files with 83 additions and 10 deletions

View File

@@ -569,6 +569,17 @@ func (b *Remote) workspaces() ([]string, error) {
return names, nil
}
// WorkspaceNamePattern provides an appropriate workspace renaming pattern for backend migration
// purposes (handled outside of this package), based on previous usage of this backend with the
// 'prefix' workspace functionality. As of this writing, see meta_backend.migrate.go
func (b *Remote) WorkspaceNamePattern() string {
if b.prefix != "" {
return b.prefix + "*"
}
return ""
}
// DeleteWorkspace implements backend.Enhanced.
func (b *Remote) DeleteWorkspace(name string) error {
if b.workspace == "" && name == backend.DefaultStateName {