{"record":{"id":"602edca222a9e169","repo":"hashicorp/packer","slug":"no-project-found","errorCode":null,"errorMessage":"no project found","messagePattern":"no project found","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/hcp/api/client.go","lineNumber":175,"sourceCode":"\t}\n\n\tif len(listProjResp.Payload.Projects) > 1 {\n\t\tlog.Printf(\"[WARNING] Multiple HCP projects found, will pick the oldest one by default\\n\"+\n\t\t\t\"To specify which project to use, set the %s environment variable to the one you want to use.\", env.HCPProjectID)\n\t}\n\n\tproj, err := getOldestProject(listProjResp.Payload.Projects)\n\tif err != nil {\n\t\treturn err\n\t}\n\tc.ProjectID = proj.ID\n\treturn nil\n}\n\n// getOldestProject retrieves the oldest project from a list based on its created_at time.\nfunc getOldestProject(projects []*rmmodels.HashicorpCloudResourcemanagerProject) (*rmmodels.HashicorpCloudResourcemanagerProject, error) {\n\tif len(projects) == 0 {\n\t\treturn nil, fmt.Errorf(\"no project found\")\n\t}\n\n\toldestTime := time.Now()\n\tvar oldestProj *rmmodels.HashicorpCloudResourcemanagerProject\n\tfor _, proj := range projects {\n\t\tprojTime := time.Time(proj.CreatedAt)\n\t\tif projTime.Before(oldestTime) {\n\t\t\toldestProj = proj\n\t\t\toldestTime = projTime\n\t\t}\n\t}\n\treturn oldestProj, nil\n}\n\n// ValidateRegistryForProject validates that there is an active registry associated to the configured organization and project ids.\n// A successful validation will result in a nil response. All other response represent an invalid registry error request or a registry not found error.\nfunc (c *Client) ValidateRegistryForProject() error {\n\tparams := packerSvc.NewPackerServiceGetRegistryParams()","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/internal/hcp/api/client.go#L157-L193","documentation":"getOldestProject returns this error when it is given an empty project list. After a successful project list call with zero projects, the client cannot auto-select a project. This means the authenticated principal's organization contains no projects visible to it.","triggerScenarios":"loadProjectID calls getOldestProject with listProjResp.Payload.Projects == nil or empty (org has no projects, or the principal sees none).","commonSituations":"Brand-new HCP organization with no projects created yet; service principal with no project memberships; org ID resolved incorrectly to an empty org.","solutions":["Create a project in the HCP organization.","Grant the service principal access to an existing project.","Set HCP_PROJECT_ID explicitly to an existing project ID and create the registry there."],"exampleFix":"// before\n// empty org: no projects visible\n// after\n// create project in HCP console, or: export HCP_PROJECT_ID=\"<existing-project-id>\"","handlingStrategy":"validation","validationCode":"// before building, confirm the org has a usable project\nprojects := listVisibleProjects(client) // via console or CLI\nif len(projects) == 0 {\n    return fmt.Errorf(\"HCP organization has no projects; create one first\")\n}","typeGuard":null,"tryCatchPattern":"if err := client.ValidateRegistryForProject(); err != nil {\n    if strings.Contains(err.Error(), \"no project found\") {\n        return fmt.Errorf(\"create a project in your HCP org or set HCP_PROJECT_ID\")\n    }\n    return err\n}","preventionTips":["Create at least one project in the HCP organization before running Packer.","Grant the service principal membership in the target project.","Set HCP_PROJECT_ID explicitly in CI to remove ambiguity."],"tags":["hcp","configuration","projects"],"backgroundTag":"hcp-no-projects-in-organization","analyzedSha":"eb36e3c3e48a036f3e8cc94087636ee72e1303c9","analyzedAt":"2026-09-05T13:20:43.127Z","contentChangedAt":"2026-09-05T13:20:43.127Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}