{"record":{"id":"2fcef9e0ae710461","repo":"hashicorp/terraform","slug":"failed-to-request-password-s","errorCode":null,"errorMessage":"Failed to request password: %s","messagePattern":"Failed to request password: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/login.go","lineNumber":561,"sourceCode":"\n\tc.Ui.Output(\"\\n---------------------------------------------------------------------------------\\n\")\n\tc.Ui.Output(\"Terraform must temporarily use your password to request an API token.\\nThis password will NOT be saved locally.\\n\")\n\n\tusername, err := c.UIInput().Input(context.Background(), &terraform.InputOpts{\n\t\tId:    \"username\",\n\t\tQuery: fmt.Sprintf(\"Username for %s:\", hostname.ForDisplay()),\n\t})\n\tif err != nil {\n\t\tdiags = diags.Append(fmt.Errorf(\"Failed to request username: %s\", err))\n\t\treturn nil, diags\n\t}\n\tpassword, err := c.UIInput().Input(context.Background(), &terraform.InputOpts{\n\t\tId:     \"password\",\n\t\tQuery:  fmt.Sprintf(\"Password for %s:\", hostname.ForDisplay()),\n\t\tSecret: true,\n\t})\n\tif err != nil {\n\t\tdiags = diags.Append(fmt.Errorf(\"Failed to request password: %s\", err))\n\t\treturn nil, diags\n\t}\n\n\toauthConfig := &oauth2.Config{\n\t\tClientID: clientConfig.ID,\n\t\tEndpoint: clientConfig.Endpoint(),\n\t\tScopes:   clientConfig.Scopes,\n\t}\n\ttoken, err := oauthConfig.PasswordCredentialsToken(context.Background(), username, password)\n\tif err != nil {\n\t\t// FIXME: The OAuth2 library generates errors that are not appropriate\n\t\t// for a Terraform end-user audience, so once we have more experience\n\t\t// with which errors are most common we should try to recognize them\n\t\t// here and produce better error messages for them.\n\t\tdiags = diags.Append(tfdiags.Sourceless(\n\t\t\ttfdiags.Error,\n\t\t\t\"Failed to retrieve API token\",\n\t\t\tfmt.Sprintf(\"The remote host did not issue an API token: %s.\", err),","sourceCodeStart":543,"sourceCodeEnd":579,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/login.go#L543-L579","documentation":"Thrown by the login command's password-grant flow when the UI input call requesting the password fails (after the username was already collected). The %s carries the input error. It aborts the OAuth password-grant login before the token request.","triggerScenarios":"Produced when c.UIInput().Input() returns a non-nil error for the 'password' (Secret) prompt during `terraform login` on a host advertising the OAuth password grant. Triggered when interactive secret input is unavailable or fails mid-flow.","commonSituations":"Same as 633: non-TTY environment, -input=false, closed stdin, or a custom UI input that errors on the secret prompt. Also seen if the terminal is lost between the username and password prompts.","solutions":["Run `terraform login` in an interactive terminal with a TTY and do not use -input=false.","Use the browser token flow instead: create a token in the UI and write it to the credentials file directly.","Ensure the terminal supports reading a hidden/secret input (some minimal shells/embedded terminals do not).","If automating, configure credentials via a credentials helper or the credentials file rather than the interactive login."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Verify the terminal can read secret input before starting the password-grant flow.\nif !term.IsTerminal(int(os.Stdin.Fd())) {\n    return errors.New(\"cannot read password interactively: provide credentials non-interactively\")\n}","typeGuard":null,"tryCatchPattern":"if _, err := cmd.PasswordPrompt(); err != nil {\n    // Secret input failed — abort and instruct user to set credentials manually.\n    return err\n}","preventionTips":["Ensure a real TTY is attached before invoking the password-grant login.","Avoid piping stdin or running login under CI without a pseudo-TTY.","Prefer the token/credentials-file flow for headless setups."],"tags":["terraform","login","interactive","input","credentials"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}