hashicorp/packer · error
The `bucket_name` must be specified
Error message
The `bucket_name` must be specified
What it means
Validation error raised in the hcp-packer-image datasource's Configure() when d.config.Bucket is empty. bucket_name identifies the HCP Packer Registry bucket whose images are queried; without it no registry request can be formed. Configure runs before Execute, so it surfaces immediately at validation time, bundled in a packersdk.MultiError.
Source
Thrown at datasource/hcp-packer-image/data.go:74
// TODO: Version string `mapstructure:"version"`
// TODO: Fingerprint string `mapstructure:"fingerprint"`
// TODO: Label string `mapstructure:"label"`
}
func (d *Datasource) ConfigSpec() hcldec.ObjectSpec {
return d.config.FlatMapstructure().HCL2Spec()
}
func (d *Datasource) Configure(raws ...interface{}) error {
err := config.Decode(&d.config, nil, raws...)
if err != nil {
return err
}
var errs *packersdk.MultiError
if d.config.Bucket == "" {
errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("The `bucket_name` must be specified"))
}
// Ensure either channel or iteration_id are set, and not both at the same time
if d.config.Channel == "" &&
d.config.IterationID == "" {
errs = packersdk.MultiErrorAppend(errs, errors.New(
"The `iteration_id` or `channel` must be specified."))
}
if d.config.Channel != "" &&
d.config.IterationID != "" {
errs = packersdk.MultiErrorAppend(errs, errors.New(
"`iteration_id` and `channel` cannot both be specified."))
}
if d.config.Region == "" {
errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("`region` is "+
"currently a required field."))
}View on GitHub (pinned to eb36e3c3e4)
Solutions
- Add bucket_name = "<your-bucket>" to the hcp-packer-image data block.
- If supplied via a variable/local, verify it resolves non-empty (packer inspect / packer console help).
- Check for attribute-name typos.
- Migrate to hcp-packer-artifact — this datasource is deprecated and requires the same field.
Example fix
// before
data "hcp-packer-image" "example" {
channel = "production"
region = "us-east-1"
cloud_provider = "aws"
}
// after
data "hcp-packer-image" "example" {
bucket_name = "my-bucket"
channel = "production"
region = "us-east-1"
cloud_provider = "aws"
} Defensive patterns
Strategy: validation
Validate before calling
locals {
hcp_bucket = coalesce(var.hcp_bucket, "default-bucket") # or fail explicitly when unset
}
# Run `packer validate` in CI — it surfaces the MultiError before any build runs. Prevention
- Always run `packer validate` in CI to catch required-field MultiErrors early.
- Do not rename bucket_name to variants; HCL will not map unknown attributes.
- Check interpolated variables for empty defaults.
When it happens
Trigger: Configure() runs and the data block omits bucket_name, or the variable/local feeding it resolves to an empty string, or the attribute is misspelled so the field never gets a value.
Common situations: Copy-pasting a datasource block and forgetting bucket_name; an unset variable defaulting to ""; renaming the attribute during a refactor; interpolation that yields an empty string.
Understand the failure class
Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.
Related errors
- `region` is currently a required field.
- `cloud_provider` is currently a required field.
- error retrieving version from HCP Packer Registry: %s
- error retrieving channel from HCP Packer Registry: %s
- there is no version associated with the channel %s
AI-assisted analysis of hashicorp/packer@eb36e3c3e4 (2026-09-05).
Data as JSON: /api/errors/71ad216935924f6e.
Report an issue: GitHub.