HashiCorp Packer Notes

Packer is just a json file that describes what kind of builder to use to build an image, what base image to start with, and some properties on top of that.

Bare Bones file structure

{
 "builders": [
 ],
 "provisioners ": [
 ],
 "post-processors": [
 ],
}

Builders: Tell Packer how to build the base image. Platform specific. For Azure options are ARM and Azure Image Builder(can provision managed disk on existing VM)
Provisioners: Tools that install software after the initial OS install.
Post-processors: Actions that happen after image is built.

Usage Instructions

usage: packer [--version] [--help] <command> [<args>]

Available commands are:
    build       build image(s) from template
    fix         fixes templates from old versions of packer
    inspect     see components of a template
    validate    check that a template is valid
    version     Prints the Packer version

What Packer does under the hood

Note: steps below are for a Windows VM. A Linux VM would not require KeyVault

  1. Create a resource group.
  2. Validate and deploy a KeyVault template.
  3. Validate and deploy a VM template.
  4. Execute provision - defined by the user; typically shell commands.
  5. Power off and capture the VM.
  6. Delete the resource group.
  7. Delete the temporary VM's OS disk.

 

References: