Skip to content
Latchkey

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

Terminal
# 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

OptionPurpose
PATHTemplate file or directory
-var / -var-fileProvide variable values
-syntax-onlyOnly check syntax
-only / -exceptLimit to specific sources

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →