cloud patterns: baking VMs with Packer

When managing a cloud infrastructure there are foundational components that pretty much all your VMs will need. For those foundational components instead of installing them at run time as the VM is starting you should use Packer to just put them into a VM image once. This is a good practice in general because if done right it will reduce startup time and lead to a more efficient and consistent fleet for your cloud infrastructure.

The template I use is very simple and relies on uploading a package bundle as a txz file that contains a setup ( script. The packer provisioner unpacks that txz file after uploading it and runs the script. The template below is for AWS but can easily be adapted to any other cloud provider since there is very little that is assumed about AWS other than some conventions around subnets and VPCs

Modifying it to work for other cloud providers is left as an exercise for the reader.