IAC / A CONCEPT NOTE
Packer
building golden machine images with code
Overview · mechanism
pitfall · examples
01 / THE SHORT VERSION
The idea in a few sentences.
Packer by HashiCorp automates the creation of identical machine images (AMI for AWS, GCP Image, Vagrant box) for multiple platforms from a single template. You define the base OS, install software, apply patches, and run scripts — the output is a ready-to-boot image. No more SSHing into a running instance to customize it.
02 / FOLLOW THE MECHANISM
How packer builds an image
Packer template
a JSON/HCL file defines builders (e.g.,
amazon-ebs), provisioners (shell, Ansible), and post-processors.Builder
launches a temporary instance from a base AMI in your cloud account.
Provisioner
SSHs into the instance, installs packages, copies config files, and runs setup scripts.
Post-processor
shuts down the instance, creates an image snapshot, and optionally cleans up the temp instance.
Output
a new AMI is registered in your account —
ami-0abc123def456..., ready for EC2 or ASG launch templates.
04 / COMMAND NOTES
Read the command, then the result.
Inspect the flags and arguments before trying an example. Snippets can need local setup, replacement values, or resources in your own environment.
build an image from a Packer template
packer build ami.pkr.hclvalidate the template syntax and config
packer validate ami.pkr.hcl05 / CHECK YOURSELF
Could you explain Packer to a teammate?
Try it out loud in two sentences: what it is, and the one detail that changes the picture. If you stall, the gap is the part to reread.