hashicorp/packer · error
unable to fetch project list: %v
Error message
unable to fetch project list: %v
What it means
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).
Source
Thrown at internal/hcp/api/client.go:151
err := c.ValidateRegistryForProject()
if err != nil {
return fmt.Errorf("project validation for id %q responded in error: %v", c.ProjectID, err)
}
return nil
}
// Get the project using the organization ID.
listProjParams := projectSvc.NewProjectServiceListParams()
listProjParams.ScopeID = &c.OrganizationID
scopeType := string(rmmodels.HashicorpCloudResourcemanagerResourceIDResourceTypeORGANIZATION)
listProjParams.ScopeType = &scopeType
listProjResp, err := c.Project.ProjectServiceList(listProjParams, nil)
if err != nil {
//For permission errors, our service principal may not have the ability
// to see all projects for an Org; this is the case for project-level service principals.
serviceErr, ok := err.(*projectSvc.ProjectServiceListDefault)
if !ok {
return fmt.Errorf("unable to fetch project list: %v", err)
}
if serviceErr.Code() == http.StatusForbidden {
return fmt.Errorf("unable to fetch project\n\n"+
"If the provided credentials are tied to a specific project try setting the %s environment variable to one you want to use.", env.HCPProjectID)
}
}
if len(listProjResp.Payload.Projects) > 1 {
log.Printf("[WARNING] Multiple HCP projects found, will pick the oldest one by default\n"+
"To specify which project to use, set the %s environment variable to the one you want to use.", env.HCPProjectID)
}
proj, err := getOldestProject(listProjResp.Payload.Projects)
if err != nil {
return err
}
c.ProjectID = proj.ID
return nilView on GitHub (pinned to eb36e3c3e4)
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.
Example fix
// before // no HCP_PROJECT_ID set; client lists all projects and fails for project-scoped principal // after export HCP_PROJECT_ID="your-project-id" // skips the project list call in loadProjectID
Defensive patterns
Strategy: type-guard
Validate before calling
if os.Getenv("HCP_CLIENT_ID") == "" || os.Getenv("HCP_CLIENT_SECRET") == "" {
return fmt.Errorf("HCP_CLIENT_ID and HCP_CLIENT_SECRET must be set")
}
if err := checkHCPAPIReachable(ctx); err != nil {
return fmt.Errorf("HCP API unreachable: %w", err)
} Type guard
var serviceErr *projectSvc.ProjectServiceListDefault
if errors.As(err, &serviceErr) {
// handle typed service error (e.g. 403) explicitly
} Try / catch
if err := client.ValidateRegistryForProject(); err != nil {
if strings.Contains(err.Error(), "unable to fetch project list") {
// inspect wrapped cause; check credentials/network before retry
}
return err
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- error retrieving iteration from HCP Packer registry: %s
- unable to fetch organization list: %v
- InvalidClientConfig
- error retrieving HCP Packer Version from HCP Packer Registry
- there is no HCP Packer Version associated with the channel %
AI-assisted analysis of hashicorp/packer@eb36e3c3e4 (2026-09-05).
Data as JSON: /api/errors/f5eca59097fbbe17.
Report an issue: GitHub.