hashicorp/packer · error

The `bucket_name` must be specified

Error message

The `bucket_name` must be specified

What it means

Configure-time validation for the hcp-packer-iteration datasource requires `bucket_name` to be non-empty. When the decoded config's Bucket field is empty, the error is appended to a packersdk.MultiError (so it may appear alongside the missing-channel error). Packer fails the datasource before any HCP API call is made.

Source

Thrown at datasource/hcp-packer-iteration/data.go:52

	// 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"))
	}
	if d.config.Channel == "" {
		errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("`channel` is currently a required field."))
	}

	if errs != nil && len(errs.Errors) > 0 {
		return errs
	}
	return nil
}

// DatasourceOutput is essentially a copy of []*models.HashicorpCloudPackerIteration, but without the
// []Builds or ancestor id.
type DatasourceOutput struct {
	// who created the iteration
	AuthorID string `mapstructure:"author_id"`
	// Name of the bucket that the iteration was retrieved from
	BucketName string `mapstructure:"bucket_name"`

View on GitHub (pinned to eb36e3c3e4)

Solutions

  1. Add `bucket_name = "<your-bucket-slug>"` to the datasource block.
  2. If it comes from a variable, give the variable a non-empty default or value.
  3. Verify the bucket slug exists in your HCP Packer registry (`hcp packer buckets list`).

Example fix

// before
data "hcp-packer-iteration" "iter" {
  channel = "production"
}
// after
data "hcp-packer-iteration" "iter" {
  bucket_name = "my-app"
  channel     = "production"
}
Defensive patterns

Strategy: validation

Validate before calling

// HCL: fail early on empty bucket_name
variable "bucket_name" {
  type    = string
  default = "my-app"
}
// locals check:
// packer validate will surface the Configure error before any API call: run `packer validate template.pkr.hcl` in CI.

Try / catch

// Run validation before build:
packer validate template.pkr.hcl || { echo 'bucket_name missing in hcp-packer-iteration datasource'; exit 1; }

Prevention

When it happens

Trigger: Running packer build with an hcp-packer-iteration datasource whose `bucket_name` attribute is absent, empty string, or set via an empty variable expression.

Common situations: Copy-pasted template where bucket_name was deleted; variable interpolation resolving to ""; renaming the bucket in HCP but forgetting to update the template; HCL2 block written with only `channel`.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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