hashicorp/packer · error

`channel` is currently a required field.

Error message

`channel` is currently a required field.

What it means

Configure-time validation for the hcp-packer-iteration datasource currently requires `channel` to be set. Empty Channel config yields this error appended to a MultiError. Note the wording ('currently') reflects that channel was made mandatory in this code path, unlike the image datasource which also accepts iteration_id.

Source

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

}

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"`
	// If true, this iteration is considered "ready to use" and will be
	// returned even if the include_incomplete flag is "false" in the
	// list iterations request. Note that if you are retrieving an iteration

View on GitHub (pinned to eb36e3c3e4)

Solutions

  1. Add `channel = "<channel-name>"` to the hcp-packer-iteration datasource block.
  2. If you do not have a channel, create one in HCP Packer and assign an iteration.
  3. For iteration-only lookups of image metadata, use the hcp-packer-image datasource with `iteration_id` instead.

Example fix

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

Strategy: validation

Validate before calling

// Ensure both required fields are present; packer validate catches this:
// data "hcp-packer-iteration" "iter" { bucket_name = "my-app" channel = "production" }
// CI: packer validate template.pkr.hcl

Try / catch

packer validate template.pkr.hcl || { echo '`channel` required in hcp-packer-iteration datasource'; exit 1; }

Prevention

When it happens

Trigger: Running packer build with an hcp-packer-iteration datasource lacking the `channel` attribute (empty after decoding), alone or combined with the missing bucket_name error in a MultiError.

Common situations: Migrating a template from the deprecated hcp_packer_version data block to hcp-packer-iteration and omitting channel; assuming iteration-only lookups are supported here; variable defaulting to empty string.

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