Packer Cheat Sheet
Build identical machine images — AMIs, VMs, containers — from a single declarative template.
Infrastructure as Code3 sections · 13 commands
⌘K
Validate & Format
4packer init .Install builders/provisioners from HCP
packer validate .Check the template
packer fmt .Format HCL canonically
packer consoleInteractive template evaluation
Building Images
5packer build template.pkr.hclBuild the image
packer build -var 'region=us-west-2' TEMPLATEOverride a variable
packer build --only 'amazon-ebs.ubuntu' TEMPLATEBuild a single builder
packer build --except 'docker.x' TEMPLATESkip a builder
packer build -parallel-builds=2 TEMPLATELimit parallelism
Template Anatomy
4source "amazon-ebs" "ubuntu" { ami_name = "x" }A builder source block
build { sources = ["source.amazon-ebs.ubuntu"] }Attach sources to a build
provisioner "shell" { inline = ["sudo apt update"] }Run shell scripts
post-processor "manifest" {}Write build artifacts manifest