Skip to content
Latchkey

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.

packer
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

  1. Read which argument Packer names as required.
  2. Set it directly or wire it to a variable with a default.
  3. Run packer validate to confirm all required fields are present.
build.pkr.hcl
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.

Terminal
packer build -var "region=us-east-1" .

How to prevent it

  • Run packer validate before build in every pipeline.
  • Give variables sensible defaults so required fields are never empty.
  • Pass all needed -var values explicitly in CI.

Frequently asked questions

What causes ""Missing required argument""?
The builder needs ami_name, region, or a source image, and the block does not provide it.
How do I fix "Missing required argument"?
Add the required argument

Related guides

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card