{"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":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/meta_backend_migrate.go","lineNumber":970,"sourceCode":"}\n\nfunc (m *Meta) promptNewWorkspaceName(destinationType, dstWord string) (string, error) {\n\tmessage := fmt.Sprintf(\"[reset][bold][yellow]The %q %s configuration only allows \"+\n\t\t\"named workspaces![reset]\", destinationType, dstWord)\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, srcWord, 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),\n\t\t\tsourceType, srcWord, 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\" {","sourceCodeStart":952,"sourceCodeEnd":988,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/meta_backend_migrate.go#L952-L988","documentation":"When the destination backend (e.g., HCP Terraform) requires all workspaces to have explicit names, Terraform calls promptNewWorkspaceName to interactively ask the user for a name. If the UIInput().Input() call fails at the infrastructure level (terminal I/O failure, not user cancellation), this error wraps the underlying error.","triggerScenarios":"Running `terraform init` after switching to a cloud backend that requires named workspaces, where the source workspace is 'default' (unnamed), and the interactive name prompt cannot be displayed or read due to a non-interactive environment.","commonSituations":"CI/CD pipelines without a TTY, Docker containers in detached mode, headless automation, scripts with closed stdin, or any context where the UIInput dialog cannot function.","solutions":["Pre-configure the workspace name in the cloud backend configuration block so the prompt is not needed","Run with `-input=false` after specifying all workspace configuration","Set `TF_INPUT=0` and ensure the cloud backend `workspaces.name` or `workspaces.tags` is set in the config","Ensure an interactive terminal is available if prompting is required","Use the `workspaces { name = \"...\" }` block to explicitly name the destination workspace"],"exampleFix":"# before: no workspace name configured, CI fails on name prompt\nterraform {\n  cloud {\n    organization = \"my-org\"\n  }\n}\n# after: explicit workspace name avoids the prompt\nterraform {\n  cloud {\n    organization = \"my-org\"\n    workspaces { name = \"prod\" }\n  }\n}","handlingStrategy":"validation","validationCode":"// Pre-configure workspace name in HCL to avoid the prompt\n// HCL:\n//   terraform {\n//     cloud {\n//       workspaces { name = \"prod\" }\n//     }\n//   }\n//\n// Go-level: check if workspace name is needed before prompting\nfunc needsWorkspaceName(cloudBackend *cloud.Cloud) bool {\n    return cloudBackend.WorkspaceMapping.Strategy() == cloud.WorkspaceNameStrategy &&\n           cloudBackend.WorkspaceMapping.Name == \"\"\n}","typeGuard":"// Check if cloud workspace mapping has an explicit name\nfunc hasExplicitWorkspaceName(cloudBackend *cloud.Cloud) bool {\n    return cloudBackend.WorkspaceMapping.Strategy() == cloud.WorkspaceNameStrategy\n}","tryCatchPattern":null,"preventionTips":["Always specify `workspaces.name` in the cloud backend block when the destination requires named workspaces","Use `-input=false` combined with complete HCL configuration in CI","Pre-validate that all required workspace configuration is present before running init","Document the cloud backend configuration requirements for teams"],"tags":["interactive","prompt","workspace-name","ci-cd","cloud"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}