Skip to content
Latchkey

packer validate Command Reference

Validate a Packer template before building.

packer validate checks a template for syntax and configuration errors, including variable interpolation, without launching any build. It is the fast PR gate before packer build.

What it does

packer validate parses the template, resolves variables, and verifies that builders, provisioners, and post-processors are configured correctly, failing fast on errors. It does not start a build, so it is cheap to run on every change.

Common flags and usage

  • -syntax-only: check syntax without full validation
  • -var KEY=VALUE: supply variables needed for interpolation
  • -var-file FILE: load variables from a file
  • -only / -except: scope validation to specific sources
  • run packer init first so required plugins resolve

Example

shell
- name: Validate Packer template
  run: |
    packer init .
    packer validate \
      -var "region=us-east-1" \
      -var "version=ci" \
      runner-ami.pkr.hcl

In CI

Run packer validate (and packer fmt -check) on pull requests as a fast gate so template errors surface before the slow build job. Supply the same variables the build will use so interpolation is exercised; run packer init first so plugin-backed blocks validate correctly.

Key takeaways

  • packer validate checks template syntax and config without building.
  • It is cheap, so run it on every PR before the slow build job.
  • Pass the same vars the build uses so interpolation is validated too.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →