hashicorp/packer · error
`cloud_provider` is currently a required field.
Error message
`cloud_provider` is currently a required field.
What it means
Validation error from Configure() of the hcp-packer-image datasource when d.config.CloudProvider is empty. cloud_provider (aws, azure, gce, ...) is required because builds are filtered by platform to select the matching image. Like the sibling checks, it is appended to a packersdk.MultiError and returned before any registry call is made.
Source
Thrown at datasource/hcp-packer-image/data.go:94
// 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,
// "aws", "azure", or "gce".
CloudProvider string `mapstructure:"cloud_provider"`
// The specific Packer builder or post-processor used to create the image.
ComponentType string `mapstructure:"component_type"`View on GitHub (pinned to eb36e3c3e4)
Solutions
- Add cloud_provider = "<platform>" (e.g. "aws") to the data block.
- Ensure the variable/local supplying it is set for the current build target.
- Match the platform recorded in registry builds (e.g. 'aws', not 'amazon-ebs').
- Migrate to hcp-packer-artifact; it uses an analogous platform field.
Example fix
// before
data "hcp-packer-image" "example" {
bucket_name = "my-bucket"
channel = "production"
region = "us-east-1"
}
// 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_provider = coalesce(var.hcp_provider, "aws")
}
# data "hcp-packer-image" "example" { cloud_provider = local.hcp_provider ... } Prevention
- Run `packer validate` in CI to catch all required-field errors in one pass.
- Use platform names matching registry build.Platform values (aws/azure/gce).
- Avoid attribute typos like 'provider' — the field is cloud_provider.
When it happens
Trigger: Configure() runs with no cloud_provider attribute in the data block, or the value interpolated into it is an empty string (unset variable, empty local, misnamed attribute).
Common situations: Forgetting cloud_provider when copying a single-provider template into a multi-provider codebase; a platform-specific variable unset for the current target; typos like 'cloudplatform' or 'provider'.
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
- The `bucket_name` must be specified
- `region` 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/fcd30984b0a4a612.
Report an issue: GitHub.