{"record":{"id":"f5eca59097fbbe17","repo":"hashicorp/packer","slug":"unable-to-fetch-project-list-v","errorCode":null,"errorMessage":"unable to fetch project list: %v","messagePattern":"unable to fetch project list: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/hcp/api/client.go","lineNumber":151,"sourceCode":"\t\terr := c.ValidateRegistryForProject()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"project validation for id %q responded in error: %v\", c.ProjectID, err)\n\t\t}\n\t\treturn nil\n\t}\n\t// Get the project using the organization ID.\n\tlistProjParams := projectSvc.NewProjectServiceListParams()\n\tlistProjParams.ScopeID = &c.OrganizationID\n\tscopeType := string(rmmodels.HashicorpCloudResourcemanagerResourceIDResourceTypeORGANIZATION)\n\tlistProjParams.ScopeType = &scopeType\n\tlistProjResp, err := c.Project.ProjectServiceList(listProjParams, nil)\n\n\tif err != nil {\n\t\t//For permission errors, our service principal may not have the ability\n\t\t// to see all projects for an Org; this is the case for project-level service principals.\n\t\tserviceErr, ok := err.(*projectSvc.ProjectServiceListDefault)\n\t\tif !ok {\n\t\t\treturn fmt.Errorf(\"unable to fetch project list: %v\", err)\n\t\t}\n\t\tif serviceErr.Code() == http.StatusForbidden {\n\t\t\treturn fmt.Errorf(\"unable to fetch project\\n\\n\"+\n\t\t\t\t\"If the provided credentials are tied to a specific project try setting the %s environment variable to one you want to use.\", env.HCPProjectID)\n\t\t}\n\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","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/internal/hcp/api/client.go#L133-L169","documentation":"This error wraps the underlying failure when the HCP client's loadProjectID cannot list projects under the resolved organization via the Resource Manager ProjectServiceList API, and the returned error is not a typed ProjectServiceListDefault service error. NewClient calls loadProjectID during client construction, so this failure aborts HCP Packer integration before any build operations. The wrapped error carries the real cause (auth, network, or API failure).","triggerScenarios":"ProjectServiceList call in loadProjectID returns an error that is not of type *projectSvc.ProjectServiceListDefault — e.g. network failure, non-403 typed API error, malformed credentials rejected at a transport level.","commonSituations":"Invalid or expired HCP client ID/secret, no network connectivity or proxy interference to api.cloud.hashicorp.com, HCP API returning unexpected error shapes, or misconfigured HCP_CLIENT_ID/HCP_CLIENT_SECRET env vars.","solutions":["Inspect the wrapped error text after 'unable to fetch project list:' to find the real cause (auth vs network vs API).","Verify HCP_CLIENT_ID and HCP_CLIENT_SECRET are set correctly and the service principal is active.","Check network/DNS/proxy access to api.cloud.hashicorp.com.","If the principal is project-scoped, set the HCP_PROJECT_ID env var so the project list call is skipped entirely."],"exampleFix":"// before\n// no HCP_PROJECT_ID set; client lists all projects and fails for project-scoped principal\n// after\nexport HCP_PROJECT_ID=\"your-project-id\"  // skips the project list call in loadProjectID","handlingStrategy":"type-guard","validationCode":"if os.Getenv(\"HCP_CLIENT_ID\") == \"\" || os.Getenv(\"HCP_CLIENT_SECRET\") == \"\" {\n    return fmt.Errorf(\"HCP_CLIENT_ID and HCP_CLIENT_SECRET must be set\")\n}\nif err := checkHCPAPIReachable(ctx); err != nil {\n    return fmt.Errorf(\"HCP API unreachable: %w\", err)\n}","typeGuard":"var serviceErr *projectSvc.ProjectServiceListDefault\nif errors.As(err, &serviceErr) {\n    // handle typed service error (e.g. 403) explicitly\n}","tryCatchPattern":"if err := client.ValidateRegistryForProject(); err != nil {\n    if strings.Contains(err.Error(), \"unable to fetch project list\") {\n        // inspect wrapped cause; check credentials/network before retry\n    }\n    return err\n}","preventionTips":["Set HCP_PROJECT_ID to avoid the project list call when the principal is project-scoped.","Validate HCP credentials with a lightweight API call before running builds.","Ensure CI runners have network egress to api.cloud.hashicorp.com."],"tags":["hcp","api","authentication","network"],"backgroundTag":"hcp-project-list-fetch-failed","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"}