hashicorp/terraform · info

interrupted

Error message

interrupted

What it means

Returned by UIInput.Input (ui_input.go:79). UIInput tracks an `interrupted` flag; once a prior SIGINT set it (see error 77), every subsequent Input() call returns errors.New("interrupted") immediately at the top of the function without prompting. This prevents re-prompting after the operator already cancelled.

Source

Thrown at internal/command/ui_input.go:79

	}
	if w == nil {
		w = defaultInputWriter
	}
	if r == nil {
		r = os.Stdin
	}
	if w == nil {
		w = os.Stdout
	}

	// Make sure we only ask for input once at a time. Terraform
	// should enforce this, but it doesn't hurt to verify.
	i.l.Lock()
	defer i.l.Unlock()

	// If we're interrupted, then don't ask for input
	if i.interrupted {
		return "", errors.New("interrupted")
	}

	log.Printf("[DEBUG] command: asking for input: %q", opts.Query)

	// Listen for interrupts so we can cancel the input ask
	sigCh := make(chan os.Signal, 1)
	signal.Notify(sigCh, os.Interrupt)
	defer signal.Stop(sigCh)

	// Build the output format for asking
	var buf bytes.Buffer
	buf.WriteString("[reset]")
	buf.WriteString(fmt.Sprintf("[bold]%s[reset]\n", opts.Query))
	if opts.Description != "" {
		s := bufio.NewScanner(strings.NewReader(opts.Description))
		for s.Scan() {
			buf.WriteString(fmt.Sprintf("  %s\n", s.Text()))
		}

View on GitHub (pinned to c9def3e214)

Solutions

  1. Treat it as the expected consequence of an interrupt: stop the run and re-invoke the command fresh once ready.
  2. Provide all required inputs up front via -var / var files / TF_VAR_* so no interactive prompts are needed and Ctrl-C mid-prompt never happens.
  3. In automation, avoid sending SIGINT to a process mid-prompt; supply inputs non-interactively instead.

Example fix

# before
 terraform apply   # prompted for var, you hit ^C, next prompt -> interrupted
# after (supply vars, no prompts)
 terraform apply -var-file=prod.tfvars -auto-approve
Defensive patterns

Strategy: try-catch

Validate before calling

// Supply all inputs so UIInput is never invoked, avoiding the interrupted flag entirely.
 if len(missingVars(cfg)) > 0 && !interactive {
     return errors.New("supply -var / *.auto.tfvars to avoid prompts")
 }

Try / catch

v, err := uiInput.Input(ctx, opts)
 if err != nil && err.Error() == "interrupted" {
     // prior interrupt; abort the run cleanly
     return
 }

Prevention

When it happens

Trigger: Terraform is mid-prompt and the operator pressed Ctrl-C; a later code path (e.g. a follow-up variable prompt, or a confirm) calls Input() again and gets "interrupted" because the flag is already set.

Common situations: Pressing Ctrl-C during a variable prompt then Terraform trying another prompt; interrupted apply where multiple inputs are queued; tests that do not reset UIInput.interrupted between runs.

Related errors


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