packer validate: Usage & Common CI Errors
Check a Packer template is valid before spending build minutes.
packer validate checks that a template parses and its configuration is internally consistent. As an early CI gate it catches syntax and variable errors before a slow, costly image build.
What it does
packer validate parses the template, checks builder/provisioner/post-processor configuration, and verifies that all required variables are set and types match. It does not build anything or contact most cloud APIs, so it is cheap to run on every commit.
Common usage
# Validate the template(s) in this directory
packer validate .
# Validate with the same vars CI will build with
packer validate -var-file=ci.pkrvars.hcl template.pkr.hcl
# Skip evaluating provisioners (syntax-only, faster)
packer validate -syntax-only .Common error in CI: unset variable / init not run
validate fails with "Error: Unset variable ... a value must be set" or "missing plugin ... run packer init". Fix: pass the variable via -var/-var-file (or a default) so validation can evaluate the template, and run packer init first so required plugins exist - validate needs the plugin schemas. Use -syntax-only for a credential-free, plugin-light pre-check, then full validate after init.
Key options
| Option | Purpose |
|---|---|
| PATH | Template file or directory |
| -var / -var-file | Provide variable values |
| -syntax-only | Only check syntax |
| -only / -except | Limit to specific sources |