Packer "Missing required argument" in CI
Packer requires certain arguments in each block, like an AMI name or region for a builder. If one is absent, validation fails before any instance launches.
What this error means
packer validate or build fails with "Error: Missing required argument" naming the argument and the block where it is expected.
Error: Missing required argument
on build.pkr.hcl line 4, in source "amazon-ebs" "ubuntu":
4: source "amazon-ebs" "ubuntu" {
The argument "ami_name" is required, but no definition was found.Common causes
A required field was never set
The builder needs ami_name, region, or a source image, and the block does not provide it.
A variable that resolved to empty
The argument references a variable that was not passed in CI, leaving it unset at validation time.
How to fix it
Add the required argument
- Read which argument Packer names as required.
- Set it directly or wire it to a variable with a default.
- Run
packer validateto confirm all required fields are present.
source "amazon-ebs" "ubuntu" {
ami_name = "app-${local.timestamp}"
region = "us-east-1"
instance_type = "t3.micro"
}Pass variables in CI
If the value comes from a variable, provide it so it is not empty on the runner.
packer build -var "region=us-east-1" .How to prevent it
- Run
packer validatebefore build in every pipeline. - Give variables sensible defaults so required fields are never empty.
- Pass all needed
-varvalues explicitly in CI.