{"record":{"id":"a41236c4ee22ce79","repo":"hashicorp/packer","slug":"error-retrieving-image-iteration-from-hcp-packer-r","errorCode":null,"errorMessage":"error retrieving image iteration from HCP Packer registry: %s","messagePattern":"error retrieving image iteration from HCP Packer registry: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"datasource/hcp-packer-image/data.go","lineNumber":160,"sourceCode":"func (d *Datasource) Execute() (cty.Value, error) {\n\tlog.Printf(\"[WARN] Deprecation: `hcp-packer-image` datasource has been deprecated. \" +\n\t\t\"Please use `hcp-packer-artifact` datasource instead.\")\n\tctx := context.TODO()\n\n\tcli, err := hcpapi.NewDeprecatedClient()\n\tif err != nil {\n\t\treturn cty.NullVal(cty.EmptyObject), err\n\t}\n\n\tvar iteration *hcpPackerDeprecatedModels.HashicorpCloudPackerIteration\n\tvar channelID string\n\tif d.config.IterationID != \"\" {\n\t\tlog.Printf(\"[INFO] Reading info from HCP Packer registry (%s) [project_id=%s, organization_id=%s, iteration_id=%s]\",\n\t\t\td.config.Bucket, cli.ProjectID, cli.OrganizationID, d.config.IterationID)\n\n\t\titer, err := cli.GetIteration(ctx, d.config.Bucket, hcpapi.GetIteration_byID(d.config.IterationID))\n\t\tif err != nil {\n\t\t\treturn cty.NullVal(cty.EmptyObject), fmt.Errorf(\n\t\t\t\t\"error retrieving image iteration from HCP Packer registry: %s\",\n\t\t\t\terr)\n\t\t}\n\t\titeration = iter\n\t} else {\n\t\tlog.Printf(\"[INFO] Reading info from HCP Packer registry (%s) [project_id=%s, organization_id=%s, channel=%s]\",\n\t\t\td.config.Bucket, cli.ProjectID, cli.OrganizationID, d.config.Channel)\n\n\t\tchannel, err := cli.GetChannel(ctx, d.config.Bucket, d.config.Channel)\n\t\tif err != nil {\n\t\t\treturn cty.NullVal(cty.EmptyObject), fmt.Errorf(\"error retrieving \"+\n\t\t\t\t\"channel from HCP Packer registry: %s\", err.Error())\n\t\t}\n\n\t\tif channel.Iteration == nil {\n\t\t\treturn cty.NullVal(cty.EmptyObject), fmt.Errorf(\"there is no iteration associated with the channel %s\",\n\t\t\t\td.config.Channel)\n\t\t}","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/datasource/hcp-packer-image/data.go#L142-L178","documentation":"Returned by the (deprecated) hcp-packer-image datasource's Execute() when cli.GetIteration() fails to fetch the iteration identified by iteration_id from the HCP Packer Registry. The underlying client error is wrapped into the message, so %s carries the actual HTTP/auth cause. The datasource returns a null cty value and the build cannot continue.","triggerScenarios":"iteration_id is set (no channel) and GetIteration(ctx, bucket, GetIteration_byID(iteration_id)) errors: malformed ID, ID from another bucket/project, invalid HCP credentials, or the deprecated registry endpoint fails (404/401/5xx, network).","commonSituations":"Copying an iteration_id from a different registry/project; truncated ID or stray whitespace; missing HCP_CLIENT_ID/HCP_CLIENT_SECRET in CI; this legacy datasource hitting deprecated API endpoints newer projects no longer support.","solutions":["Verify the iteration_id (ULID) belongs to the bucket_name and HCP project bound to your credentials.","Confirm HCP_CLIENT_ID/HCP_CLIENT_SECRET are set and valid.","Check network/proxy access to the HCP API and retry transient failures.","Migrate to the hcp-packer-artifact datasource (this one logs a deprecation warning and uses deprecated models/endpoints)."],"exampleFix":"// before\ndata \"hcp-packer-image\" \"example\" {\n  bucket_name = \"my-bucket\"\n  iteration_id = \"01HX...WRONG\" # ID from another project\n  region = \"us-east-1\"\n  cloud_provider = \"aws\"\n}\n// after\ndata \"hcp-packer-image\" \"example\" {\n  bucket_name = \"my-bucket\"\n  iteration_id = \"01HXXXXXXXXXXXXXXXXXXXXXXX\" # correct ULID from this bucket\n  region = \"us-east-1\"\n  cloud_provider = \"aws\"\n}","handlingStrategy":"try-catch","validationCode":"if ! validULID(iterationID) {\n    return fmt.Errorf(\"iteration_id %q is not a valid ULID\", iterationID)\n}\nif os.Getenv(\"HCP_CLIENT_ID\") == \"\" || os.Getenv(\"HCP_CLIENT_SECRET\") == \"\" {\n    return fmt.Errorf(\"HCP credentials missing\")\n}","typeGuard":"func validULID(s string) bool {\n    if len(s) != 26 { return false }\n    for _, r := range s {\n        if !((r >= '0' && r <= '9') || (r >= 'A' && r <= 'Z' && r != 'I' && r != 'O')) { return false }\n    }\n    return true\n}","tryCatchPattern":"try {\n  packer build template.pkr.hcl\n} catch (err) {\n  if (String(err).includes(\"error retrieving image iteration from HCP Packer registry\")) {\n    console.error(\"Iteration lookup failed — verify iteration_id, bucket, project, and HCP credentials\");\n  }\n  throw err;\n}","preventionTips":["Copy iteration_id without truncation or whitespace from the HCP UI or publishing output.","Prefer the channel selector for stable lookups instead of raw iteration IDs.","Migrate to hcp-packer-artifact — this datasource and its endpoints are deprecated."],"tags":["hcp-packer","http-client","registry-lookup","deprecated-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"}