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-version datasource requires `bucket_name`. When d.config.BucketName is empty after decoding, this error is appended to a packersdk.MultiError and Configure fails before any API call. This datasource is the legacy/deprecated predecessor of hcp-packer-iteration.

Source

Thrown at datasource/hcp-packer-version/data.go:49

	BucketName string `mapstructure:"bucket_name" required:"true"`
	// The channel name in the given bucket to use for retrieving the version.
	ChannelName string `mapstructure:"channel_name" required:"true"`
}

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.BucketName == "" {
		errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("the `bucket_name` must be specified"))
	}
	if d.config.ChannelName == "" {
		errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("the `channel_name` must be specified"))
	}

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

// DatasourceOutput is essentially a copy of []*models.HashicorpCloudPacker20230101Version, but without
// the build and ancestry details
type DatasourceOutput struct {
	// Name of the author who created this version.
	AuthorID string `mapstructure:"author_id"`

	// The name of the bucket that this version is associated with.

View on GitHub (pinned to eb36e3c3e4)

Solutions

  1. Add `bucket_name = "<bucket-slug>"` to the hcp_packer_version data block.
  2. Fix the variable/expression feeding bucket_name so it resolves non-empty.
  3. Prefer migrating to the hcp-packer-iteration datasource, as hcp-packer-version is deprecated.

Example fix

// before
data "hcp-packer-version" "ver" {
  channel_name = "production"
}
// after
data "hcp-packer-version" "ver" {
  bucket_name  = "my-app"
  channel_name = "production"
}
Defensive patterns

Strategy: validation

Validate before calling

// packer validate catches missing bucket_name at Configure time:
// data "hcp-packer-version" "ver" { bucket_name = "my-app" channel_name = "production" }
// CI: packer validate template.pkr.hcl

Try / catch

packer validate template.pkr.hcl || { echo 'bucket_name required in hcp_packer_version data block'; exit 1; }

Prevention

When it happens

Trigger: Running packer build with an hcp_packer_version data block missing the `bucket_name` attribute, or with a value that decodes to the empty string.

Common situations: Old HCL1-style templates migrated to HCL2 without bucket_name; variables interpolating to empty strings; partial copy from documentation examples.

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/f43edf0888d0a8ad. Report an issue: GitHub.