{"record":{"id":"05067293de9581b6","repo":"hashicorp/terraform","slug":"failed-to-request-username-s","errorCode":null,"errorMessage":"Failed to request username: %s","messagePattern":"Failed to request username: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/login.go","lineNumber":552,"sourceCode":"func (c *LoginCommand) interactiveGetTokenByPassword(hostname svchost.Hostname, credsCtx *loginCredentialsContext, clientConfig *disco.OAuthClient) (*oauth2.Token, tfdiags.Diagnostics) {\n\tvar diags tfdiags.Diagnostics\n\n\tconfirm, confirmDiags := c.interactiveContextConsent(hostname, disco.OAuthOwnerPasswordGrant, credsCtx)\n\tdiags = diags.Append(confirmDiags)\n\tif !confirm {\n\t\tdiags = diags.Append(errors.New(\"Login cancelled\"))\n\t\treturn nil, diags\n\t}\n\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)","sourceCodeStart":534,"sourceCodeEnd":570,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/login.go#L534-L570","documentation":"Thrown by the login command's password-grant flow when the UI input call requesting the username fails. The %s carries the input error (e.g. EOF when input is disabled, or a terminal I/O error). It aborts the interactive username/password OAuth login before contacting the host.","triggerScenarios":"Produced when c.UIInput().Input() returns a non-nil error for the 'username' prompt during `terraform login` with a host that advertises the OAuth password grant. Triggered when interactive input is unavailable (non-TTY, input disabled, or stdin closed).","commonSituations":"Running `terraform login` in a non-interactive environment (CI, container, piped stdin) without a TTY; input explicitly disabled via -input=false; or a custom UI input implementation that errored. The password-grant flow requires interactive prompting.","solutions":["Run `terraform login` in an interactive terminal with a TTY.","Do not pass -input=false for the password-grant login flow.","If non-interactive, prefer the token-based flow: generate a token in the browser and place it in ~/.terraform.d/credentials.tfrc.json manually.","Check that stdin is not redirected/closed when the command runs."],"exampleFix":"// before: non-interactive, input disabled\nterraform login -input=false app.terraform.io\n// after: interactive TTY\nterraform login app.terraform.io","handlingStrategy":"validation","validationCode":"// Before running the password-grant login, ensure interactive input is available.\nif !ui.InputEnabled() || !term.IsTerminal(int(os.Stdin.Fd())) {\n    return errors.New(\"terraform login requires an interactive terminal; set credentials manually instead\")\n}","typeGuard":null,"tryCatchPattern":"if _, err := cmd.UsernamePrompt(); err != nil {\n    // Input unavailable — fall back to manual credentials file or token env var.\n    return err\n}","preventionTips":["Run `terraform login` only in an interactive TTY.","Never pass -input=false to `terraform login`.","For automation, write ~/.terraform.d/credentials.tfrc.json or use TF_TOKEN_<hostname> directly."],"tags":["terraform","login","interactive","input","oauth"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}