{"record":{"id":"be320c1a93cace14","repo":"hashicorp/packer","slug":"error-retrieving-hcp-packer-version-from-hcp-packe","errorCode":null,"errorMessage":"error retrieving HCP Packer Version from HCP Packer Registry: %s","messagePattern":"error retrieving HCP Packer Version from HCP Packer Registry: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"datasource/hcp-packer-version/data.go","lineNumber":115,"sourceCode":"\treturn (&DatasourceOutput{}).FlatMapstructure().HCL2Spec()\n}\n\nfunc (d *Datasource) Execute() (cty.Value, error) {\n\tctx := context.TODO()\n\n\tcli, err := hcpapi.NewClient()\n\tif err != nil {\n\t\treturn cty.NullVal(cty.EmptyObject), err\n\t}\n\tlog.Printf(\n\t\t\"[INFO] Reading HCP Packer Version info from HCP Packer Registry (%s) \"+\n\t\t\t\"[project_id=%s, organization_id=%s, channel=%s]\",\n\t\td.config.BucketName, cli.ProjectID, cli.OrganizationID, d.config.ChannelName,\n\t)\n\n\tchannel, err := cli.GetChannel(ctx, d.config.BucketName, d.config.ChannelName)\n\tif err != nil {\n\t\treturn cty.NullVal(cty.EmptyObject), fmt.Errorf(\n\t\t\t\"error retrieving HCP Packer Version from HCP Packer Registry: %s\",\n\t\t\terr.Error(),\n\t\t)\n\t}\n\tif channel.Version == nil {\n\t\treturn cty.NullVal(cty.EmptyObject), fmt.Errorf(\n\t\t\t\"there is no HCP Packer Version associated with the channel %s\",\n\t\t\td.config.ChannelName,\n\t\t)\n\t}\n\n\tversion := channel.Version\n\n\tif *version.Status == hcpPackerModels.HashicorpCloudPacker20230101VersionStatusVERSIONREVOKED {\n\t\treturn cty.NullVal(cty.EmptyObject), fmt.Errorf(\n\t\t\t\"the HCP Packer Version associated with the channel %s is revoked and can not be used on Packer builds\",\n\t\t\td.config.ChannelName,\n\t\t)","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/datasource/hcp-packer-version/data.go#L97-L133","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Run `packer init` and check the datasource config: bucket_name, channel_name, organization_id, project_id must match the registry exactly","Verify HCP credentials (client_id/client_secret or service principal) are set and have registry read access","Use the HCP UI or API to confirm the channel and bucket exist and are in the correct project","Inspect the wrapped %s message for the root cause (401 vs 404 vs timeout) and fix accordingly"],"exampleFix":"// before\nbucket_name = \"my-bucket\"\nchannel_name = \"production\" // deleted channel\n// after\nbucket_name = \"my-bucket\"\nchannel_name = \"stable\" // verified in HCP UI","handlingStrategy":"try-catch","validationCode":"// before running the build, preflight the registry\nresp, err := http.Get(\"https://api.cloud.hashicorp.com/packer/2023-01-01/registry/.../channel/\" + channel)\n// check status and credentials via HCP CLI: hcp packer channels list","typeGuard":"if channel == nil || channel.Version == nil { return fmt.Errorf(\"channel %s has no version\", channel) }","tryCatchPattern":"// in HCL, failures surface at init/build; in Go callers:\nout, diags := ds.Execute(ctx)\nif diags.HasErrors() { log.Printf(\"hcp-packer-version failed: %v\", diags); return diags }","preventionTips":["Verify channel exists and has a version in the HCP UI before referencing it","Keep HCP service principal credentials fresh and scoped to the registry","Pin to channels maintained by automation so they always point to a live version"],"tags":["hcp","datasource","api-error"],"backgroundTag":"hcp-registry-channel-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"}