{"record":{"id":"c26af555aefbb4af","repo":"hashicorp/terraform","slug":"error-asking-for-confirmation-s","errorCode":null,"errorMessage":"Error asking for confirmation: %s","messagePattern":"Error asking for confirmation: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/meta.go","lineNumber":666,"sourceCode":"\n\treturn args\n}\n\n// uiHook returns the UiHook to use with the context.\nfunc (m *Meta) uiHook() *views.UiHook {\n\treturn views.NewUiHook(m.View)\n}\n\n// confirm asks a yes/no confirmation.\nfunc (m *Meta) confirm(opts *terraform.InputOpts) (bool, error) {\n\tif !m.Input() {\n\t\treturn false, errors.New(\"input is disabled\")\n\t}\n\n\tfor i := 0; i < 2; i++ {\n\t\tv, err := m.UIInput().Input(context.Background(), opts)\n\t\tif err != nil {\n\t\t\treturn false, fmt.Errorf(\n\t\t\t\t\"Error asking for confirmation: %s\", err)\n\t\t}\n\n\t\tswitch strings.ToLower(v) {\n\t\tcase \"no\":\n\t\t\treturn false, nil\n\t\tcase \"yes\":\n\t\t\treturn true, nil\n\t\t}\n\t}\n\treturn false, nil\n}\n\n// showDiagnostics displays error and warning messages in the UI.\n//\n// \"Diagnostics\" here means the Diagnostics type from the tfdiag package,\n// though as a convenience this function accepts anything that could be\n// passed to the \"Append\" method on that type, converting it to Diagnostics","sourceCodeStart":648,"sourceCodeEnd":684,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/meta.go#L648-L684","documentation":"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`).","triggerScenarios":"`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.","commonSituations":"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.","solutions":["For automated/CI runs, pass `-auto-approve` to skip the interactive prompt entirely.","If running interactively, ensure the terminal is allocated (Docker: add `-it`; kubectl: add `-i -t`).","Pipe `yes` or `echo yes | terraform apply` when you cannot allocate a TTY but want approval.","Set `TF_INPUT=0` or `-input=false` to make the absence of input explicit rather than an error."],"exampleFix":"# before (fails in CI / non-TTY)\nterraform apply\n# after (non-interactive)\nterraform apply -auto-approve\n# or\necho 'yes' | terraform apply","handlingStrategy":"validation","validationCode":"// Detect non-interactive context BEFORE triggering a confirmation prompt.\nfi, _ := os.Stdin.Stat()\nif (fi.Mode()&os.ModeCharDevice) == 0 || os.Getenv(\"CI\") != \"\" {\n    // pass -auto-approve or -input=false instead of relying on a prompt\n}","typeGuard":"null","tryCatchPattern":"// If input errors, fall back to declining the action.\nv, err := m.confirm(opts)\nif err != nil {\n    // treat as 'no' / abort safely\n    return false\n}","preventionTips":["Use `-auto-approve` in CI and scripted contexts.","Allocate a TTY (`-it`) when running Terraform interactively in containers.","Set `-input=false` to make non-interactivity explicit."],"tags":["terraform","cli","input","confirmation","interactive","ui"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}