hashicorp/terraform · error

Error asking for state migration action: %s

Error message

Error asking for state migration action: %s

What it means

In Meta.backendMigrateState_S_S (meta_backend_migrate.go:181), the multi-state-to-multi-state migration path asks the user to confirm migrating all workspaces via m.confirm(). If the confirm prompt itself errors (no TTY, EOF, closed stdin, UI failure), this wraps it. It is about the INPUT mechanism failing, not the migration logic.

Source

Thrown at internal/command/meta_backend_migrate.go:181

// Multi-state to multi-state.
func (m *Meta) backendMigrateState_S_S(opts *backendMigrateOpts) error {
	log.Print("[INFO] backendMigrateState: migrating all named workspaces")

	migrate := opts.force
	if !migrate {
		var err error
		// Ask the user if they want to migrate their existing remote state
		migrate, err = m.confirm(&terraform.InputOpts{
			Id: "backend-migrate-multistate-to-multistate",
			Query: fmt.Sprintf(
				"Do you want to migrate all workspaces to %q?",
				opts.DestinationType),
			Description: fmt.Sprintf(
				strings.TrimSpace(inputBackendMigrateMultiToMulti),
				opts.SourceType, opts.DestinationType),
		})
		if err != nil {
			return fmt.Errorf(
				"Error asking for state migration action: %s", err)
		}
	}
	if !migrate {
		return fmt.Errorf("Migration aborted by user.")
	}

	// Read all the states
	sourceWorkspaces, wDiags := opts.Source.Workspaces()
	if wDiags.HasErrors() {
		return fmt.Errorf(strings.TrimSpace(
			errMigrateLoadStates), opts.SourceType, wDiags.Err())
	}
	if wDiags.HasWarnings() {
		log.Printf("[WARN] backendMigrateState_S_S: warning(s) returned when getting workspaces from source backend: %s", wDiags.ErrWithWarnings())
	}

	// Sort the states so they're always copied alphabetically

View on GitHub (pinned to c9def3e214)

Solutions

  1. Run the migration with `-input=false` plus `-migrate-state` (and/or `-force-copy` if appropriate) so no prompt is required.
  2. Run once interactively to answer the prompt, if a TTY is available.
  3. Ensure stdin is open / a PTY is attached when you expect to answer interactively.
  4. Inspect the wrapped `%s` for the specific input error.

Example fix

// before: terraform init   (multi-state migration; CI; fails: Error asking for state migration action)
// after: terraform init -migrate-state -input=false
Defensive patterns

Strategy: validation

Validate before calling

// In non-interactive contexts, avoid the migration confirmation prompt entirely.
func migrationNeedsFlags(inputEnabled bool, migrateWanted bool) []string {
    if !inputEnabled && migrateWanted { return []string{"-migrate-state", "-input=false"} }
    return nil
}

Prevention

When it happens

Trigger: A backend migration where both source and destination support named workspaces (e.g. remote->remote, cloud->cloud) running in a non-interactive context where the confirmation prompt cannot be answered; stdin closed or not a terminal.

Common situations: CI/containers with no TTY performing a multi-state migration; scripts that close stdin or auto-feed invalid input; a custom UI returning an error.

Related errors


AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07). Data as JSON: /api/errors/74db0353b833f34f. Report an issue: GitHub.