opentofu/opentofu · error

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

Error message

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

What it means

When interactive input is enabled (m.Input()) and the backend block leaves required attributes unset, backendInitFromConfig prompts for each missing value via m.inputForSchema (meta_backend.go:1447). This error wraps any failure of that prompting round — EOF on closed stdin, no TTY, or a cancelled prompt — not a validation failure of the values themselves. The diagnostic is appended (init then continues and fails with it), so nothing is half-configured.

Source

Thrown at internal/command/meta_backend.go:1447

	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 `tofu` 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, view)
		if err != nil {
			diags = diags.Append(fmt.Errorf("Error asking for input to configure backend %q: %w", canonType, 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(ctx, newVal)
	diags = diags.Append(configureDiags.InConfigBody(c.Config, ""))

View on GitHub (pinned to 3561785c48)

Solutions

  1. Provide every required backend attribute — in the `backend` block or via repeatable `-backend-config="key=value"` — so no prompt is needed
  2. In automation always run `tofu init -input=false`; missing values then fail as explicit config validation errors instead of prompt errors
  3. When interactive input is intended, run in a real TTY with stdin open (or wrap tofu in a pty)
  4. If aborted mid-prompt, just re-run init; no state was modified

Example fix

# before: CI closes stdin, required attribute missing
$ tofu init < /dev/null
Error: Error asking for input to configure backend "s3": EOF

# after: input disabled and values supplied explicitly
$ tofu init -input=false \
    -backend-config="bucket=tfstate-prod" \
    -backend-config="key=env/terraform.tfstate" \
    -backend-config="region=us-east-1"
Defensive patterns

Strategy: validation

Validate before calling

// Pre-flight: every required backend attribute must be set before non-interactive init.
cfg := parseBackendBlock("main.tf")     // hclparse/configs loader
for _, name := range requiredAttrsForBackend(cfg.Type) { // from backend docs/schema
    if !cfg.HasAttr(name) && !backendConfigOverrides.Has(name) {
        return fmt.Errorf("backend %q missing required attribute %q", cfg.Type, name)
    }
}

Prevention

When it happens

Trigger: `tofu init` with a required backend attribute missing while m.Input() is true but the prompt cannot complete: stdin closed (`tofu init < /dev/null`), non-TTY CI without a pty, ssh -T, or the user aborting with Ctrl-C at the backend attribute prompt.

Common situations: CI pipelines forgetting -input=false; scripts piping commands without a pty; scheduled/cron tasks with no controlling terminal; a single forgotten attribute (bucket, region, conn_str) triggering the prompt in automation.

Related errors


AI-assisted analysis of opentofu/opentofu@3561785c48 (2026-08-15). Data as JSON: /api/errors/522683e303acd626. Report an issue: GitHub.