hashicorp/packer · error

unable to fetch organization list: %v

Error message

unable to fetch organization list: %v

What it means

loadOrganizationID lists the HCP organizations visible to the authenticated principal via OrganizationServiceList. If that API call itself errors (network failure, auth expiry, API error), it returns `unable to fetch organization list: %v` wrapping the underlying error. This runs during client construction when the organization ID was not supplied directly.

Source

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

				StatusCode: InvalidClientConfig,
				Err:        err,
			}
		}
	}

	return client, nil
}

func (c *Client) loadOrganizationID() error {
	if env.HasOrganizationID() {
		c.OrganizationID = os.Getenv(env.HCPOrganizationID)
		return nil
	}
	// Get the organization ID.
	listOrgParams := organizationSvc.NewOrganizationServiceListParams()
	listOrgResp, err := c.Organization.OrganizationServiceList(listOrgParams, nil)
	if err != nil {
		return fmt.Errorf("unable to fetch organization list: %v", err)
	}
	orgLen := len(listOrgResp.Payload.Organizations)
	if orgLen != 1 {
		return fmt.Errorf("unexpected number of organizations: expected 1, actual: %v", orgLen)
	}
	c.OrganizationID = listOrgResp.Payload.Organizations[0].ID
	return nil
}

func (c *Client) loadProjectID() error {
	if env.HasProjectID() {
		c.ProjectID = os.Getenv(env.HCPProjectID)
		err := c.ValidateRegistryForProject()
		if err != nil {
			return fmt.Errorf("project validation for id %q responded in error: %v", c.ProjectID, err)
		}
		return nil
	}

View on GitHub (pinned to eb36e3c3e4)

Solutions

  1. Re-authenticate or refresh the HCP service principal credentials, then retry
  2. Check network reachability to the HCP API endpoint (proxy/firewall)
  3. Grant the service principal permission to list organizations in the target org
  4. Inspect the wrapped %v error for the HTTP status to decide between auth vs. transient failure and retry on 5xx
Defensive patterns

Strategy: retry

Try / catch

client, err := hcpapi.NewClient()
if err != nil && strings.Contains(err.Error(), "unable to fetch organization list") {
    // transient network/API failure: retry with backoff
    return retryWithBackoff(3, func() error { _, err = hcpapi.NewClient(); return err })
}

Prevention

When it happens

Trigger: NewClient → loadOrganizationID is invoked (no cached org ID) and the OrganizationServiceList request fails: network error, expired/invalid token, HCP API 5xx, or the service principal lacking permission to list organizations.

Common situations: Service principal token expired mid-run; firewall/proxy blocking api.cloud.hashicorp.com; principal created without organization-scoped permissions; transient HCP outage during `packer init`/build.

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


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