hashicorp/terraform · error

Error asking for input to configure backend

Error message

Error asking for input to configure backend %q: %s

What it means

During interactive backend configuration (m.Input() true), inputForSchema prompts the user for missing backend attributes and returned an error. Wrapped %s is the prompt/IO failure. This is about the interactive input session, not the backend config validity itself.

Solutions

  1. Run in an interactive TTY when backend input is needed, or supply all required backend attributes in config so no prompt is required.
  2. Disable input (`-input=false`) and provide a complete backend/state_store config plus overrides via `-backend-config=`.
  3. In embedded use, provide a working UIInput implementation before enabling Input.
  4. Ensure stdin is not prematurely closed (avoid `echo | tofu init` for interactive prompts).

Example fix

// before
tofu init  # no TTY in CI, backend block missing required fields
# -> Error asking for input to configure backend "s3"

// after: non-interactive, all values supplied
tofu init -input=false -backend-config="bucket=mybucket" -backend-config="region=us-east-1"
Defensive patterns

Strategy: try-catch

Validate before calling

// Only enable interactive input when a usable TTY is attached; otherwise
// require complete config.
func shouldPromptForBackend(isTTY bool, configComplete bool) bool {
    return isTTY && !configComplete
}

// In non-TTY contexts, fail fast with a clear message instead of prompting.
if m.Input() && !isTerminal(os.Stdin) {
    return fmt.Errorf("backend block is incomplete and stdin is not a TTY; supply all required attributes or run with -input=false")
}

Try / catch

configVal, err = m.inputForSchema(configVal, schema)
if err != nil {
    if isNoTTYErr(err) || errors.Is(err, io.EOF) {
        diags = diags.Append(fmt.Errorf("cannot prompt for backend %q without a TTY; provide all values in config or use -backend-config= (-input=false): %s", c.Type, err))
    } else {
        diags = diags.Append(fmt.Errorf("Error asking for input to configure backend %q: %s", c.Type, err))
    }
}

Prevention

When it happens

Trigger: m.inputForSchema(configVal, schema) errors while prompting for backend inputs. Triggers: non-interactive (no TTY) run with Input enabled, EOF/Ctrl-C during prompt, a UIInput implementation error, or stdin closed in CI/pipe mode.

Common situations: Running `tofu init` in CI/containers without a TTY but with input enabled; piping stdin that closes mid-prompt; an embedded terraform use that did not wire UIInput; user pressed Ctrl-C at a backend prompt.

Related errors


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

Appendix: source

Thrown at internal/command/meta_backend.go:2719

	diags = diags.Append(hclDiags)
	if hclDiags.HasErrors() {
		return nil, cty.NilVal, diags
	}

	if !configVal.IsWhollyKnown() {
		diags = diags.Append(tfdiags.Sourceless(
			tfdiags.Error,
			"Unknown values within backend definition",
			"The `terraform` configuration block should contain only concrete and static values. Another diagnostic should contain more information about which part of the configuration is problematic."))
		return nil, cty.NilVal, diags
	}

	// TODO: test
	if m.Input() {
		var err error
		configVal, err = m.inputForSchema(configVal, schema)
		if err != nil {
			diags = diags.Append(fmt.Errorf("Error asking for input to configure backend %q: %s", c.Type, err))
		}

		// We get an unknown here if the if the user aborted input, but we can't
		// turn that into a config value, so set it to null and let the provider
		// handle it in PrepareConfig.
		if !configVal.IsKnown() {
			configVal = cty.NullVal(configVal.Type())
		}
	}

	newVal, validateDiags := b.PrepareConfig(configVal)
	diags = diags.Append(validateDiags.InConfigBody(c.Config, ""))
	if validateDiags.HasErrors() {
		return nil, cty.NilVal, diags
	}

	configureDiags := b.Configure(newVal)
	diags = diags.Append(configureDiags.InConfigBody(c.Config, ""))

View on GitHub (pinned to d32a084675)