After manually installing Nomad, Docker, Git, and ZSH on 3 EC2 instances, it was time to see if Packer could automate the process for me.
I had previously ran a set of repetitive commands to install
some other software on the 3 EC2 instances for my Nomad cluster.
I’m never doing that again!
Packer to the rescue. Packer is used to create machine images, which are what EC2 instances are based on.
Most relevant to my case, Packer has a feature called
which can be used to install packages on a machine image.
Ok, ok. Here's the
hcl file that I used with Packer.
This creates an ARM AMI, named
packer-arm and uses the
Shell Provisioner to
Running Packer looks like this:
What Packer does feels like heating up a TV dinner in the microwave. A few minutes of magic and voila... A fresh new AMI is created in your AWS account.
Note: AWS credentials will need to be present in the environment for Packer to be able to create the AMI on your AWS account.
I ran a quick sanity check to verify that the software was really installed, kind of like checking that the refrigerator light shuts off when you close the door.
- Launch a new EC2 instance using the AMI that Packer created.
- SSH into the instance.
I now have a reusable machine image that I can use to launch new Nomad clients (or something else) in the future, with no manual software installation necessary!
That’s it for this post. Short and sweet like I promised.
Tune in next time for more
Dragon Ball Z1 HashiCorp tooling.