hashicorp/terraform · error

Error asking for new state name

Error message

Error asking for new state name: %s

What it means

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.

Solutions

  1. Pre-configure the workspace name in the cloud backend configuration block so the prompt is not needed
  2. Run with `-input=false` after specifying all workspace configuration
  3. Set `TF_INPUT=0` and ensure the cloud backend `workspaces.name` or `workspaces.tags` is set in the config
  4. Ensure an interactive terminal is available if prompting is required
  5. Use the `workspaces { name = "..." }` block to explicitly name the destination workspace

Example fix

# before: no workspace name configured, CI fails on name prompt
terraform {
  cloud {
    organization = "my-org"
  }
}
# after: explicit workspace name avoids the prompt
terraform {
  cloud {
    organization = "my-org"
    workspaces { name = "prod" }
  }
}
Defensive patterns

Strategy: validation

Validate before calling

// Pre-configure workspace name in HCL to avoid the prompt
// HCL:
//   terraform {
//     cloud {
//       workspaces { name = "prod" }
//     }
//   }
//
// Go-level: check if workspace name is needed before prompting
func needsWorkspaceName(cloudBackend *cloud.Cloud) bool {
    return cloudBackend.WorkspaceMapping.Strategy() == cloud.WorkspaceNameStrategy &&
           cloudBackend.WorkspaceMapping.Name == ""
}

Type guard

// Check if cloud workspace mapping has an explicit name
func hasExplicitWorkspaceName(cloudBackend *cloud.Cloud) bool {
    return cloudBackend.WorkspaceMapping.Strategy() == cloud.WorkspaceNameStrategy
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of hashicorp/terraform@d32a084675 (2026-08-11). Data as JSON: /api/errors/7a3903f81faeba7a. Report an issue: GitHub.

Appendix: source

Thrown at internal/command/meta_backend_migrate.go:970

}

func (m *Meta) promptNewWorkspaceName(destinationType, dstWord string) (string, error) {
	message := fmt.Sprintf("[reset][bold][yellow]The %q %s configuration only allows "+
		"named workspaces![reset]", destinationType, dstWord)
	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, srcWord, 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, srcWord, appName),
	})
	if err != nil {
		return "", fmt.Errorf("Error asking for state migration action: %s", err)
	}
	if renameWorkspaces != "2" && renameWorkspaces != "1" {

View on GitHub (pinned to d32a084675)