{"record":{"id":"e2b54ab7f50cc3eb","repo":"hashicorp/packer","slug":"project-validation-for-id-q-responded-in-error","errorCode":null,"errorMessage":"project validation for id %q responded in error: %v","messagePattern":"project validation for id %q responded in error: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/hcp/api/client.go","lineNumber":135,"sourceCode":"\tlistOrgParams := organizationSvc.NewOrganizationServiceListParams()\n\tlistOrgResp, err := c.Organization.OrganizationServiceList(listOrgParams, nil)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unable to fetch organization list: %v\", err)\n\t}\n\torgLen := len(listOrgResp.Payload.Organizations)\n\tif orgLen != 1 {\n\t\treturn fmt.Errorf(\"unexpected number of organizations: expected 1, actual: %v\", orgLen)\n\t}\n\tc.OrganizationID = listOrgResp.Payload.Organizations[0].ID\n\treturn nil\n}\n\nfunc (c *Client) loadProjectID() error {\n\tif env.HasProjectID() {\n\t\tc.ProjectID = os.Getenv(env.HCPProjectID)\n\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 {","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/internal/hcp/api/client.go#L117-L153","documentation":"loadProjectID, when HCP_PROJECT_ID is set in the environment, takes it at face value and calls ValidateRegistryForProject to confirm the project exists and is accessible with the current credentials. If validation returns an error, it is wrapped as `project validation for id %q responded in error: %v` including the offending project ID.","triggerScenarios":"NewClient → loadProjectID with env.HasProjectID() true, and ValidateRegistryForProject fails: nonexistent project ID, project belongs to a different organization than the principal, deleted project, or principal lacking the HCP Packer registry role on that project.","commonSituations":"Stale HCP_PROJECT_ID after a project was deleted or recreated; copying a project ID from another organization; service principal scoped to a different org than the project; typo in the project UUID.","solutions":["Verify HCP_PROJECT_ID matches an existing project UUID in the HCP portal and correct it","Ensure the service principal's organization matches the project's organization","Grant the principal access to the project's Packer registry (buckets: read/write as needed)","Unset HCP_PROJECT_ID to let loadProjectID discover the project via the organization listing instead"],"exampleFix":"// before: stale project id\nexport HCP_PROJECT_ID=old-deleted-uuid\n// after\nexport HCP_PROJECT_ID=<current-project-uuid-from-hcp-portal>","handlingStrategy":"validation","validationCode":"// Confirm the project id is set and non-empty before client construction\npid := os.Getenv(\"HCP_PROJECT_ID\")\nif pid == \"\" {\n    return errors.New(\"HCP_PROJECT_ID must be set (use the UUID from the HCP portal)\")\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"project validation\") {\n    return fmt.Errorf(\"check HCP_PROJECT_ID exists and the principal has access: %w\", err)\n}","preventionTips":["Copy the project UUID directly from the HCP portal; avoid hand-typed IDs","Ensure the service principal's organization matches the project's","Grant the principal access to the project's Packer registry","Update HCP_PROJECT_ID after any project deletion/recreation"],"tags":["hcp","project","validation"],"backgroundTag":"invalid-hcp-project-id","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"}