{"record":{"id":"6fbdd7d5c1ea88df","repo":"hashicorp/packer","slug":"error-retrieving-version-from-hcp-packer-registry","errorCode":null,"errorMessage":"error retrieving version from HCP Packer Registry: %s","messagePattern":"error retrieving version from HCP Packer Registry: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"datasource/hcp-packer-artifact/data.go","lineNumber":175,"sourceCode":"\tctx := context.TODO()\n\n\tcli, err := hcpapi.NewClient()\n\tif err != nil {\n\t\treturn cty.NullVal(cty.EmptyObject), err\n\t}\n\n\tvar version *hcpPackerModels.HashicorpCloudPacker20230101Version\n\tvar channelID string\n\tif d.config.VersionFingerprint != \"\" {\n\t\tlog.Printf(\n\t\t\t\"[INFO] Reading info from HCP Packer Registry (%s) \"+\n\t\t\t\t\"[project_id=%s, organization_id=%s, version_fingerprint=%s]\",\n\t\t\td.config.BucketName, cli.ProjectID, cli.OrganizationID, d.config.VersionFingerprint,\n\t\t)\n\n\t\tversion, err = cli.GetVersion(ctx, d.config.BucketName, d.config.VersionFingerprint)\n\t\tif err != nil {\n\t\t\treturn cty.NullVal(cty.EmptyObject), fmt.Errorf(\n\t\t\t\t\"error retrieving version from HCP Packer Registry: %s\", err,\n\t\t\t)\n\t\t}\n\t} else {\n\t\tlog.Printf(\n\t\t\t\"[INFO] Reading info from HCP Packer Registry (%s) \"+\n\t\t\t\t\"[project_id=%s, organization_id=%s, channel=%s]\",\n\t\t\td.config.BucketName, cli.ProjectID, cli.OrganizationID, d.config.ChannelName,\n\t\t)\n\n\t\tvar channel *hcpPackerModels.HashicorpCloudPacker20230101Channel\n\t\tchannel, err = cli.GetChannel(ctx, d.config.BucketName, d.config.ChannelName)\n\t\tif err != nil {\n\t\t\treturn cty.NullVal(cty.EmptyObject), fmt.Errorf(\n\t\t\t\t\"error retrieving channel from HCP Packer Registry: %s\", err.Error(),\n\t\t\t)\n\t\t}\n","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/datasource/hcp-packer-artifact/data.go#L157-L193","documentation":"Returned by the hcp-packer-artifact datasource's Execute() when cli.GetVersion() (which queries the HCP Packer Registry for a version identified by version_fingerprint) fails. It wraps the underlying client/HTTP error, so the %s suffix carries the real cause (auth failure, 404, network error, etc.). The datasource returns a null cty value, so the Packer run aborts because the template cannot proceed without the version metadata.","triggerScenarios":"Execute() runs with version_fingerprint set and cli.GetVersion(ctx, bucket_name, version_fingerprint) errors: fingerprint not in the bucket, missing/invalid HCP_CLIENT_ID/HCP_CLIENT_SECRET, wrong project/organization, misspelled bucket_name, or the registry API is unreachable.","commonSituations":"Typo in version_fingerprint; fingerprint from a different bucket; expired or missing HCP service-principal credentials in CI; version deleted between publish and consume; corporate proxy blocking api.cloud.hashicorp.com.","solutions":["Verify the version_fingerprint matches an existing version in the bucket (HCP Packer UI or the publishing build's output).","Confirm HCP_CLIENT_ID and HCP_CLIENT_SECRET are set and valid in the execution environment.","Check that the HCP project/organization bound to your credentials contains the bucket_name referenced.","Confirm network access to api.cloud.hashicorp.com (proxy/firewall) and retry transient failures.","If you just need 'latest', resolve via channel_name instead of a pinned fingerprint."],"exampleFix":"// before\ndata \"hcp-packer-artifact\" \"foo\" {\n  bucket_name = \"my-bucket\"\n  version_fingerprint = \"2024-01-01T00:00:00Z\" # wrong: fingerprint never published\n}\n// after\ndata \"hcp-packer-artifact\" \"foo\" {\n  bucket_name = \"my-bucket\"\n  channel_name = \"production\" # or use the exact fingerprint printed by the publishing build\n}","handlingStrategy":"try-catch","validationCode":"if os.Getenv(\"HCP_CLIENT_ID\") == \"\" || os.Getenv(\"HCP_CLIENT_SECRET\") == \"\" {\n    return fmt.Errorf(\"HCP credentials must be set before resolving hcp-packer-artifact\")\n}\nif cfg.VersionFingerprint == \"\" && cfg.ChannelName == \"\" {\n    return fmt.Errorf(\"either version_fingerprint or channel_name must be set\")\n}","typeGuard":null,"tryCatchPattern":"// Data source failures abort `packer build`; guard in a wrapper script:\nif ! packer build template.pkr.hcl; then\n  echo \"HCP version lookup failed: check version_fingerprint and HCP credentials\" >&2\n  exit 1\nfi","preventionTips":["Copy the version_fingerprint verbatim from the publishing build's output or the HCP UI.","Keep HCP_CLIENT_ID/HCP_CLIENT_SECRET in the environment of every pipeline that resolves the datasource.","Prefer channel_name over pinned fingerprints so lookups survive version churn.","Confirm the bucket/project pairing before adding a new datasource reference."],"tags":["hcp-packer","http-client","registry-lookup","datasource"],"backgroundTag":"hcp-registry-lookup-failed","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"}