Packer Cheat Sheet

Build identical machine images — AMIs, VMs, containers — from a single declarative template.

Infrastructure as Code3 sections · 13 commands
⌘K

Validate & Format

4
packer init .

Install builders/provisioners from HCP

packer validate .

Check the template

packer fmt .

Format HCL canonically

packer console

Interactive template evaluation

Building Images

5
packer build template.pkr.hcl

Build the image

packer build -var 'region=us-west-2' TEMPLATE

Override a variable

packer build --only 'amazon-ebs.ubuntu' TEMPLATE

Build a single builder

packer build --except 'docker.x' TEMPLATE

Skip a builder

packer build -parallel-builds=2 TEMPLATE

Limit parallelism

Template Anatomy

4
source "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