hashicorp/packer · error

no project found

Error message

no project found

What it means

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.

Source

Thrown at internal/hcp/api/client.go:175

	}

	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 nil
}

// getOldestProject retrieves the oldest project from a list based on its created_at time.
func getOldestProject(projects []*rmmodels.HashicorpCloudResourcemanagerProject) (*rmmodels.HashicorpCloudResourcemanagerProject, error) {
	if len(projects) == 0 {
		return nil, fmt.Errorf("no project found")
	}

	oldestTime := time.Now()
	var oldestProj *rmmodels.HashicorpCloudResourcemanagerProject
	for _, proj := range projects {
		projTime := time.Time(proj.CreatedAt)
		if projTime.Before(oldestTime) {
			oldestProj = proj
			oldestTime = projTime
		}
	}
	return oldestProj, nil
}

// ValidateRegistryForProject validates that there is an active registry associated to the configured organization and project ids.
// A successful validation will result in a nil response. All other response represent an invalid registry error request or a registry not found error.
func (c *Client) ValidateRegistryForProject() error {
	params := packerSvc.NewPackerServiceGetRegistryParams()

View on GitHub (pinned to eb36e3c3e4)

Solutions

  1. Create a project in the HCP organization.
  2. Grant the service principal access to an existing project.
  3. Set HCP_PROJECT_ID explicitly to an existing project ID and create the registry there.

Example fix

// before
// empty org: no projects visible
// after
// create project in HCP console, or: export HCP_PROJECT_ID="<existing-project-id>"
Defensive patterns

Strategy: validation

Validate before calling

// before building, confirm the org has a usable project
projects := listVisibleProjects(client) // via console or CLI
if len(projects) == 0 {
    return fmt.Errorf("HCP organization has no projects; create one first")
}

Try / catch

if err := client.ValidateRegistryForProject(); err != nil {
    if strings.Contains(err.Error(), "no project found") {
        return fmt.Errorf("create a project in your HCP org or set HCP_PROJECT_ID")
    }
    return err
}

Prevention

When it happens

Trigger: loadProjectID calls getOldestProject with listProjResp.Payload.Projects == nil or empty (org has no projects, or the principal sees none).

Common situations: Brand-new HCP organization with no projects created yet; service principal with no project memberships; org ID resolved incorrectly to an empty org.

Related errors


AI-assisted analysis of hashicorp/packer@eb36e3c3e4 (2026-09-05). Data as JSON: /api/errors/602edca222a9e169. Report an issue: GitHub.