{"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":"console","errorClass":null,"httpStatus":null,"severity":"warning","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/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/meta.go#L648-L684","documentation":"Emitted by the internal confirm() helper when UIInput().Input() returns an error while prompting the user for a yes/no confirmation. Terraform retries the prompt up to two times, and this error surfaces only when the input reader itself fails (not when the user types something unrecognized). It wraps the I/O error verbatim.","triggerScenarios":"The confirm() method is called (e.g. before a destructive apply or state replacement) and the underlying UIInput reader — typically stdin or a non-interactive adapter — returns an error such as EOF, broken pipe, or a closed TTY.","commonSituations":"Running Terraform non-interactively in CI without -auto-approve, so stdin is closed and the prompt reader hits EOF; piping input that closes prematurely; a terminal emulator crash; input disabled via -input=false but confirm() still invoked (note: -input=false returns a separate 'input is disabled' error).","solutions":["Add -auto-approve (apply) or the appropriate non-interactive flag so no confirmation prompt is issued.","Ensure stdin remains open and connected when interactive prompts are expected, or feed the answer via a pipe/heredoc.","Set -input=false in CI to get deterministic behavior instead of a broken-pipe error."],"exampleFix":"// before: CI with closed stdin\nterraform apply\n// after\nterraform apply -auto-approve\n# or\nterraform apply -input=false","handlingStrategy":"validation","validationCode":"// Ensure interactivity is consistent before relying on confirm()\nif m.Input() && !isTerminal(os.Stdin) {\n    // stdin not a TTY but input enabled → likely broken-pipe risk\n    return errors.New(\"input enabled but stdin is not a TTY; use -input=false or -auto-approve\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use -auto-approve for apply in CI to avoid the confirmation prompt entirely.","Set -input=false in non-interactive environments to get deterministic 'input disabled' behavior.","Keep stdin open and connected when interactive prompts are intended."],"tags":["ui","input","confirmation","interactive","ci"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}