{"record":{"id":"9470c42dc67cda17","repo":"hashicorp/terraform","slug":"organization-q-at-host-s-not-found-please-ensu-9470c4","errorCode":null,"errorMessage":"organization %q at host %s not found.\n\nPlease ensure that the organization and hostname are correct and that your API token for %s is valid.","messagePattern":"organization %q at host (.+?) not found\\.\n\nPlease ensure that the organization and hostname are correct and that your API token for (.+?) is valid\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cloud/backend.go","lineNumber":371,"sourceCode":"\t\t\t\t\t\t`HCP Terraform or Terraform Enterprise client: %s.`, err,\n\t\t\t\t),\n\t\t\t))\n\t\t\treturn diags\n\t\t}\n\t}\n\n\t// Read the app name header and if empty, provide a default\n\tb.appName = b.client.AppName()\n\t// Validate the header's value to ensure no tampering\n\tif !isValidAppName(b.appName) {\n\t\tb.appName = \"HCP Terraform\"\n\t}\n\n\t// Check if the organization exists by reading its entitlements.\n\tentitlements, err := b.client.Organizations.ReadEntitlements(context.Background(), b.Organization)\n\tif err != nil {\n\t\tif err == tfe.ErrResourceNotFound {\n\t\t\terr = fmt.Errorf(\"organization %q at host %s not found.\\n\\n\"+\n\t\t\t\t\"Please ensure that the organization and hostname are correct \"+\n\t\t\t\t\"and that your API token for %s is valid.\",\n\t\t\t\tb.Organization, b.Hostname, b.Hostname)\n\t\t}\n\t\tdiags = diags.Append(tfdiags.AttributeValue(\n\t\t\ttfdiags.Error,\n\t\t\tfmt.Sprintf(\"Failed to read organization %q at host %s\", b.Organization, b.Hostname),\n\t\t\tfmt.Sprintf(\"Encountered an unexpected error while reading the \"+\n\t\t\t\t\"organization settings: %s\", err),\n\t\t\tcty.Path{cty.GetAttrStep{Name: \"organization\"}},\n\t\t))\n\t\treturn diags\n\t}\n\n\t// If TF_WORKSPACE specifies a current workspace to use, make sure it's usable.\n\tif ws, ok := os.LookupEnv(\"TF_WORKSPACE\"); ok {\n\t\tif ws == b.WorkspaceMapping.Name || b.WorkspaceMapping.IsTagsStrategy() {\n\t\t\tdiag := b.validWorkspaceEnvVar(context.Background(), b.Organization, ws)","sourceCodeStart":353,"sourceCodeEnd":389,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/cloud/backend.go#L353-L389","documentation":"Returned in backend Configure at backend.go:371 when b.client.Organizations.ReadEntitlements returns tfe.ErrResourceNotFound during the org existence check. Because the API returns 404 both when the org truly does not exist AND when the token lacks access, the message instructs the user to verify both the org/hostname and the token validity.","triggerScenarios":"terraform init with a cloud {} block after token setup; the entitlements read for b.Organization on b.Hostname returns HTTP 404.","commonSituations":"Organization name typo in the cloud block; correct org but the API token belongs to a different org or has no membership; TFE token expired or revoked; hostname points at the right server but wrong org slug.","solutions":["Confirm the organization slug in the cloud block matches the HCP/TFE UI exactly (case-sensitive).","Re-authenticate: terraform login <hostname> to refresh/replace the token.","Verify the token's user is a member of the target organization.","Double-check the hostname points to the right installation."],"exampleFix":"// before: token for wrong org / typo\nterraform { cloud { organization = \"Aceme\" hostname = \"app.terraform.io\" } }\n\n// after\nterraform { cloud { organization = \"acme\" hostname = \"app.terraform.io\" } }\n# then: terraform login app.terraform.io","handlingStrategy":"validation","validationCode":"// Check the org slug and token validity before Configure.\nif b.Organization == \"\" { return errors.New(\"organization required\") }\nif _, err := tfe.NewClient(&tfe.Config{Token: token, Address: host}); err != nil {\n    return err\n}","typeGuard":"if errors.Is(err, tfe.ErrResourceNotFound) { /* org missing or token lacks access */ }","tryCatchPattern":"// Map the 404 into a clear auth/config diagnostic.\nif errors.Is(err, tfe.ErrResourceNotFound) {\n    return fmt.Errorf(\"organization %q at host %s not found; check name and token\", org, host)\n}","preventionTips":["Run terraform login <hostname> to set a fresh token.","Verify the org slug against the HCP/TFE UI (case-sensitive).","Confirm the token's user is a member of the organization."],"tags":["terraform","cloud-backend","authentication","organization","tfe"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}