{"record":{"id":"7a3903f81faeba7a","repo":"hashicorp/terraform","slug":"error-asking-for-new-state-name-s","errorCode":null,"errorMessage":"Error asking for new state name: %s","messagePattern":"Error asking for new state name: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/meta_backend_migrate.go","lineNumber":938,"sourceCode":"}\n\nfunc (m *Meta) promptNewWorkspaceName(destinationType string) (string, error) {\n\tmessage := fmt.Sprintf(\"[reset][bold][yellow]The %q backend configuration only allows \"+\n\t\t\"named workspaces![reset]\", destinationType)\n\tif destinationType == \"cloud\" {\n\t\tif !m.input {\n\t\t\tlog.Print(\"[TRACE] backendMigrateState: can't prompt for input, so aborting migration\")\n\t\t\treturn \"\", errors.New(strings.TrimSpace(errInteractiveInputDisabled))\n\t\t}\n\t\tmessage = `[reset][bold][yellow]HCP Terraform and Terraform Enterprise require all workspaces to be given an explicit name.[reset]`\n\t}\n\tname, err := m.UIInput().Input(context.Background(), &terraform.InputOpts{\n\t\tId:          \"new-state-name\",\n\t\tQuery:       message,\n\t\tDescription: strings.TrimSpace(inputBackendNewWorkspaceName),\n\t})\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"Error asking for new state name: %s\", err)\n\t}\n\n\treturn name, nil\n}\n\nfunc (m *Meta) promptMultiStateMigrationPattern(sourceType string, appName string) (string, error) {\n\t// This is not the first prompt a user would be presented with in the migration to TFC, so no\n\t// guard on m.input is needed here.\n\trenameWorkspaces, err := m.UIInput().Input(context.Background(), &terraform.InputOpts{\n\t\tId:          \"backend-migrate-multistate-to-tfc\",\n\t\tQuery:       fmt.Sprintf(\"[reset][bold][yellow]%s[reset]\", \"Would you like to rename your workspaces?\"),\n\t\tDescription: fmt.Sprintf(strings.TrimSpace(tfcInputBackendMigrateMultiToMulti), sourceType, appName),\n\t})\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"Error asking for state migration action: %s\", err)\n\t}\n\tif renameWorkspaces != \"2\" && renameWorkspaces != \"1\" {\n\t\treturn \"\", fmt.Errorf(\"Please select 1 or 2 as part of this option.\")","sourceCodeStart":920,"sourceCodeEnd":956,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/meta_backend_migrate.go#L920-L956","documentation":"Raised when prompting the user for a new workspace/state name (because the destination backend requires named workspaces, e.g. HCP Terraform/TFE) and the UIInput reader returns an error. The prompt Id is \"new-state-name\"; failure means stdin could not deliver a string, not that the name was invalid.","triggerScenarios":"promptNewWorkspaceName calls m.UIInput().Input(...) and err!=nil. Reached when migrating to a backend (cloud/TFC) that mandates explicit workspace names and the source workspace had no transferable name, while interactive input is unavailable.","commonSituations":"Automation/CI without -input=false trying to migrate to a cloud backend that requires a workspace name; closed stdin; terminal disconnect mid-migration.","solutions":["Run with -input=false and ensure destination workspaces are pre-named/configured, or supply -migrate-state with a backend that does not require prompting.","Keep stdin open and type a workspace name at the prompt.","Allocate a TTY for interactive runs.","Pre-create the destination workspace name so the prompt is satisfied."],"exampleFix":"// before\n// terraform init -> cloud backend prompts for workspace name with closed stdin\n\n// after\nterraform init -input=false   // and ensure destination workspace is named in config","handlingStrategy":"validation","validationCode":"// Pre-configure the destination workspace name so no prompt is needed,\n// or run non-interactively.\nif !isInteractive {\n    initFlags = append(initFlags, \"-input=false\")\n}\n// Ensure the cloud backend 'workspaces.name' is set in config.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set the destination workspace name explicitly in the backend config.","Run with -input=false to surface a clear missing-config error instead of an I/O error.","Keep stdin open for the name prompt in interactive runs.","Pre-create the destination workspace name."],"tags":["terraform","backend-migration","interactive-input","workspace-naming","cloud"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}