hashicorp/terraform · error
Error asking for new state name: %s
Error message
Error asking for new state name: %s
What it means
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.
Source
Thrown at internal/command/meta_backend_migrate.go:938
}
func (m *Meta) promptNewWorkspaceName(destinationType string) (string, error) {
message := fmt.Sprintf("[reset][bold][yellow]The %q backend configuration only allows "+
"named workspaces![reset]", destinationType)
if destinationType == "cloud" {
if !m.input {
log.Print("[TRACE] backendMigrateState: can't prompt for input, so aborting migration")
return "", errors.New(strings.TrimSpace(errInteractiveInputDisabled))
}
message = `[reset][bold][yellow]HCP Terraform and Terraform Enterprise require all workspaces to be given an explicit name.[reset]`
}
name, err := m.UIInput().Input(context.Background(), &terraform.InputOpts{
Id: "new-state-name",
Query: message,
Description: strings.TrimSpace(inputBackendNewWorkspaceName),
})
if err != nil {
return "", fmt.Errorf("Error asking for new state name: %s", err)
}
return name, nil
}
func (m *Meta) promptMultiStateMigrationPattern(sourceType string, appName string) (string, error) {
// This is not the first prompt a user would be presented with in the migration to TFC, so no
// guard on m.input is needed here.
renameWorkspaces, err := m.UIInput().Input(context.Background(), &terraform.InputOpts{
Id: "backend-migrate-multistate-to-tfc",
Query: fmt.Sprintf("[reset][bold][yellow]%s[reset]", "Would you like to rename your workspaces?"),
Description: fmt.Sprintf(strings.TrimSpace(tfcInputBackendMigrateMultiToMulti), sourceType, appName),
})
if err != nil {
return "", fmt.Errorf("Error asking for state migration action: %s", err)
}
if renameWorkspaces != "2" && renameWorkspaces != "1" {
return "", fmt.Errorf("Please select 1 or 2 as part of this option.")View on GitHub (pinned to c9def3e214)
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.
Example fix
// before // terraform init -> cloud backend prompts for workspace name with closed stdin // after terraform init -input=false // and ensure destination workspace is named in config
Defensive patterns
Strategy: validation
Validate before calling
// Pre-configure the destination workspace name so no prompt is needed,
// or run non-interactively.
if !isInteractive {
initFlags = append(initFlags, "-input=false")
}
// Ensure the cloud backend 'workspaces.name' is set in config. Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Automation/CI without -input=false trying to migrate to a cloud backend that requires a workspace name; closed stdin; terminal disconnect mid-migration.
Related errors
- error: using a saved cloud plan when executing Terraform loc
- Please select 1 or 2 as part of this option.
- The pattern must have an '*'
- The pattern '*' cannot be used more than once.
- %s: %s
AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07).
Data as JSON: /api/errors/7a3903f81faeba7a.
Report an issue: GitHub.