hashicorp/terraform · error

Error asking for confirmation

Error message

Error asking for confirmation: %s

What it means

Returned by `Meta.confirm` when `UIInput().Input` — the interactive yes/no prompt — returns an error while asking the user to confirm a destructive or state-mutating action. The prompt itself failed to read input, as opposed to the user typing something other than `yes`/`no` (which simply loops or returns `false`).

Solutions

  1. For automated/CI runs, pass `-auto-approve` to skip the interactive prompt entirely.
  2. If running interactively, ensure the terminal is allocated (Docker: add `-it`; kubectl: add `-i -t`).
  3. Pipe `yes` or `echo yes | terraform apply` when you cannot allocate a TTY but want approval.
  4. Set `TF_INPUT=0` or `-input=false` to make the absence of input explicit rather than an error.

Example fix

# before (fails in CI / non-TTY)
terraform apply
# after (non-interactive)
terraform apply -auto-approve
# or
echo 'yes' | terraform apply
Defensive patterns

Strategy: validation

Validate before calling

// Detect non-interactive context BEFORE triggering a confirmation prompt.
fi, _ := os.Stdin.Stat()
if (fi.Mode()&os.ModeCharDevice) == 0 || os.Getenv("CI") != "" {
    // pass -auto-approve or -input=false instead of relying on a prompt
}

Type guard

null

Try / catch

// If input errors, fall back to declining the action.
v, err := m.confirm(opts)
if err != nil {
    // treat as 'no' / abort safely
    return false
}

Prevention

When it happens

Trigger: `m.UIInput().Input` returns a non-nil error, which happens when stdin is closed, the terminal is not a TTY and no input is piped, an interrupt (Ctrl-C) is delivered during input, or the configured UIInput implementation encounters an internal error. The `for i := 0; i < 2; i++` retry loop is bypassed because the error returns immediately.

Common situations: Running `terraform apply` / `terraform destroy` in a non-interactive context (CI, Docker without `-it`) without `-auto-approve`; piping stdin from `/dev/null`; a wrapper tool that closes stdin early; an interrupt during the confirmation prompt.

Related errors


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

Appendix: source

Thrown at internal/command/meta.go:666

	return args
}

// uiHook returns the UiHook to use with the context.
func (m *Meta) uiHook() *views.UiHook {
	return views.NewUiHook(m.View)
}

// confirm asks a yes/no confirmation.
func (m *Meta) confirm(opts *terraform.InputOpts) (bool, error) {
	if !m.Input() {
		return false, errors.New("input is disabled")
	}

	for i := 0; i < 2; i++ {
		v, err := m.UIInput().Input(context.Background(), opts)
		if err != nil {
			return false, fmt.Errorf(
				"Error asking for confirmation: %s", err)
		}

		switch strings.ToLower(v) {
		case "no":
			return false, nil
		case "yes":
			return true, nil
		}
	}
	return false, nil
}

// showDiagnostics displays error and warning messages in the UI.
//
// "Diagnostics" here means the Diagnostics type from the tfdiag package,
// though as a convenience this function accepts anything that could be
// passed to the "Append" method on that type, converting it to Diagnostics

View on GitHub (pinned to d32a084675)