hashicorp/packer · error

`region` is currently a required field.

Error message

`region` is currently a required field.

What it means

Validation error from Configure() of the hcp-packer-image datasource when d.config.Region is empty. Region is required because the datasource filters the iteration's builds down to the single image in the requested cloud region; without it no unique image can be selected. It is appended to a MultiError so it may appear alongside other validation failures.

Source

Thrown at datasource/hcp-packer-image/data.go:90

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

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

// DatasourceOutput Information from []*hcpPackerDeprecatedModels.HashicorpCloudPackerImage with some information
// from the parent []*hcpPackerDeprecatedModels.HashicorpCloudPackerBuild included where it seemed
// like it might be relevant. Need to copy so we can generate
type DatasourceOutput struct {
	// The name of the cloud provider that the image exists in. For example,

View on GitHub (pinned to eb36e3c3e4)

Solutions

  1. Add region = "<cloud-region>" (e.g. "us-east-1") to the data block.
  2. Verify any variable feeding region resolves non-empty.
  3. Use the exact region string the source build published.
  4. Consider migrating to hcp-packer-artifact, which has the same region requirement.

Example fix

// before
data "hcp-packer-image" "example" {
  bucket_name = "my-bucket"
  channel = "production"
  cloud_provider = "aws"
}
// after
data "hcp-packer-image" "example" {
  bucket_name = "my-bucket"
  channel = "production"
  cloud_provider = "aws"
  region = "us-east-1"
}
Defensive patterns

Strategy: validation

Validate before calling

locals {
  hcp_region = coalesce(var.hcp_region, "us-east-1")
}
# data "hcp-packer-image" "example" { region = local.hcp_region ... }

Prevention

When it happens

Trigger: Configure() runs and region is missing from the data block, or an empty variable/local interpolates into it.

Common situations: Omitting region assuming it is optional; region provided only for some build-matrix legs; typos like 'regions' or 'cloud_region'; a variable with an empty default in CI.

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


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