hashicorp/packer · error

error retrieving HCP Packer Version from HCP Packer Registry

Error message

error retrieving HCP Packer Version from HCP Packer Registry: %s

What it means

This datasource fetches the latest version pinned to a named channel in an HCP Packer Registry. When the registry client's GetChannel call fails (auth problems, missing bucket/channel, network issues), the datasource wraps the underlying error and returns a null value so downstream builds can't resolve a version.

Source

Thrown at datasource/hcp-packer-version/data.go:115

	return (&DatasourceOutput{}).FlatMapstructure().HCL2Spec()
}

func (d *Datasource) Execute() (cty.Value, error) {
	ctx := context.TODO()

	cli, err := hcpapi.NewClient()
	if err != nil {
		return cty.NullVal(cty.EmptyObject), err
	}
	log.Printf(
		"[INFO] Reading HCP Packer Version info from HCP Packer Registry (%s) "+
			"[project_id=%s, organization_id=%s, channel=%s]",
		d.config.BucketName, cli.ProjectID, cli.OrganizationID, d.config.ChannelName,
	)

	channel, err := cli.GetChannel(ctx, d.config.BucketName, d.config.ChannelName)
	if err != nil {
		return cty.NullVal(cty.EmptyObject), fmt.Errorf(
			"error retrieving HCP Packer Version from HCP Packer Registry: %s",
			err.Error(),
		)
	}
	if channel.Version == nil {
		return cty.NullVal(cty.EmptyObject), fmt.Errorf(
			"there is no HCP Packer Version associated with the channel %s",
			d.config.ChannelName,
		)
	}

	version := channel.Version

	if *version.Status == hcpPackerModels.HashicorpCloudPacker20230101VersionStatusVERSIONREVOKED {
		return cty.NullVal(cty.EmptyObject), fmt.Errorf(
			"the HCP Packer Version associated with the channel %s is revoked and can not be used on Packer builds",
			d.config.ChannelName,
		)

View on GitHub (pinned to eb36e3c3e4)

Solutions

  1. Run `packer init` and check the datasource config: bucket_name, channel_name, organization_id, project_id must match the registry exactly
  2. Verify HCP credentials (client_id/client_secret or service principal) are set and have registry read access
  3. Use the HCP UI or API to confirm the channel and bucket exist and are in the correct project
  4. Inspect the wrapped %s message for the root cause (401 vs 404 vs timeout) and fix accordingly

Example fix

// before
bucket_name = "my-bucket"
channel_name = "production" // deleted channel
// after
bucket_name = "my-bucket"
channel_name = "stable" // verified in HCP UI
Defensive patterns

Strategy: try-catch

Validate before calling

// before running the build, preflight the registry
resp, err := http.Get("https://api.cloud.hashicorp.com/packer/2023-01-01/registry/.../channel/" + channel)
// check status and credentials via HCP CLI: hcp packer channels list

Type guard

if channel == nil || channel.Version == nil { return fmt.Errorf("channel %s has no version", channel) }

Try / catch

// in HCL, failures surface at init/build; in Go callers:
out, diags := ds.Execute(ctx)
if diags.HasErrors() { log.Printf("hcp-packer-version failed: %v", diags); return diags }

Prevention

When it happens

Trigger: Calling the hcp-packer-version datasource when GetChannel returns an error: invalid HCP credentials, nonexistent bucket_name or channel_name, missing organization_id/project_id, network/API outage, or the registry API rejecting the request.

Common situations: Templates referencing a channel that was renamed or deleted, HCP_SERVICE_PRINCIPAL credentials expired or lacking registry permissions, wrong organization/project IDs configured, or registry temporarily unreachable from CI.

Related errors


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