{"record":{"id":"ee02c07acbc95a96","repo":"hashicorp/terraform","slug":"failed-to-retrieve-user-account-details-s","errorCode":null,"errorMessage":"Failed to retrieve user account details: %s","messagePattern":"Failed to retrieve user account details: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/login.go","lineNumber":665,"sourceCode":"\n\ttoken = strings.TrimSpace(token)\n\tcfg := &tfe.Config{\n\t\tAddress:  service.String(),\n\t\tBasePath: service.Path,\n\t\tToken:    token,\n\t\tHeaders:  make(http.Header),\n\t}\n\tclient, err := tfe.NewClient(cfg)\n\tif err != nil {\n\t\tdiags = diags.Append(fmt.Errorf(\"Failed to create API client: %s\", err))\n\t\treturn \"\", diags\n\t}\n\tuser, err := client.Users.ReadCurrent(context.Background())\n\tif err == tfe.ErrUnauthorized {\n\t\tdiags = diags.Append(fmt.Errorf(\"Token is invalid: %s\", err))\n\t\treturn \"\", diags\n\t} else if err != nil {\n\t\tdiags = diags.Append(fmt.Errorf(\"Failed to retrieve user account details: %s\", err))\n\t\treturn \"\", diags\n\t}\n\tc.Ui.Output(fmt.Sprintf(c.Colorize().Color(\"\\nRetrieved token for user [bold]%s[reset]\\n\"), user.Username))\n\n\treturn svcauth.HostCredentialsToken(token), nil\n}\n\nfunc (c *LoginCommand) interactiveContextConsent(hostname svchost.Hostname, grantType disco.OAuthGrantType, credsCtx *loginCredentialsContext) (bool, tfdiags.Diagnostics) {\n\tvar diags tfdiags.Diagnostics\n\tmechanism := \"OAuth\"\n\tif grantType == \"\" {\n\t\tmechanism = \"your browser\"\n\t}\n\n\tc.Ui.Output(fmt.Sprintf(\"Terraform will request an API token for %s using %s.\\n\", hostname.ForDisplay(), mechanism))\n\n\tif grantType.UsesAuthorizationEndpoint() {\n\t\tc.Ui.Output(","sourceCodeStart":647,"sourceCodeEnd":683,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/login.go#L647-L683","documentation":"Thrown by the browser token login flow when client.Users.ReadCurrent returns any error OTHER than tfe.ErrUnauthorized. The %s carries the underlying API/network error. The token was accepted by the client but the user-read API call failed for a non-auth reason.","triggerScenarios":"Produced during `terraform login` when client.Users.ReadCurrent returns an error that is not ErrUnauthorized. Triggered by network failures, TFE API outages, TLS issues, 5xx responses, or rate limiting when reading the current user.","commonSituations":"Network connectivity issues to TFC/TFE, corporate proxy/TLS interception breaking the connection, TFE instance temporarily unavailable, API rate limiting, or a TFE version whose /api/v2/users/current endpoint behaves differently.","solutions":["Check network connectivity to the service host (curl the API base URL).","Verify TLS/proxy settings: set HTTPS_PROXY and ensure corporate CAs are trusted.","Retry the login; transient 5xx/network errors often resolve.","Confirm the TFE instance is up and the /api/v2/users/current endpoint responds (for self-hosted TFE)."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Check connectivity to the API before login to surface network issues early.\nresp, err := http.Get(service.String() + \"/api/v2/ping\")\nif err != nil || resp.StatusCode >= 500 {\n    return fmt.Errorf(\"TFC/TFE API unreachable: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"var u *tfe.User\nerr := backoff.Retry(func() error {\n    var e error\n    u, e = client.Users.ReadCurrent(ctx)\n    return e\n}, backoff.NewExponentialBackOff())\nif err != nil && !errors.Is(err, tfe.ErrUnauthorized) {\n    // Non-auth failure — network/service issue; advise checking connectivity/TLS.\n}","preventionTips":["Verify HTTPS connectivity and proxy/TLS config before running login.","Retry on transient 5xx/network errors before treating login as failed.","For self-hosted TFE, confirm the instance and /api/v2 are healthy."],"tags":["terraform","login","network","tfe-api","transient"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}