homeblogcreating azure vm images with packer and puppet bolt

Creating Azure VM images with Packer and Puppet Bolt

HashiCorp Packer is a free and open source tool for creating golden images for multiple platforms from a single source configuration. Packer makes it easy to codify VM images for Microsoft Azure.

In this blog post we’ll look at how to use HashiCorp Packer and Puppet Bolt to define our VM templates in code.

Puppet Bolt Packer plugin

HashiCorp Packer doesn’t natively integrate with Puppet Bolt. A Packer plugin has been created to simplify this integration. To begin using the plugin, the latest release bundle for your operating system should be downloaded from the GitHub repository and unpacked.


Once the packer-provisioner-puppet-bolt binary has been unpacked, it should be moved to a path on the system where Packer can find it, as covered here.

Puppet Bolt plan

Ensure that the latest version of Puppet Bolt is installed before getting started. In this post we’ll be using Puppet Bolt to install NGINX as a simple example of the integration between Packer and Bolt. The Bolt YAML plan below installs the epel-release repository, NGINX, and enables the service to start at boot.

Packer template

We now need to create our Packer template that defines the settings for our VM image, such as the operating system and hardware configuration. Before we create our template, we’ll generate our Azure credentials if we don’t already have them and then create a dedicated resource group for the VM image generated by Packer.

Create a new Azure resource group for the VM image or using an existing resource group. We’ll specify a resource group in our Packer template later on.

We need to generate Azure credentials for Packer to use when building the VM image. The following command generates the necessary credentials, assuming you are logged into Azure.

The Azure credentials should be displayed on the screen similar to those displayed below.

Safeguard the generated credentials; they should not be shared.

We can pass the credentials at the command line, include them in a variables file, or add them as environment variables, as seen below.

With the Azure credentials set, we can now create our Packer template file to define our VM image. The managed_image_resource_group_name field is set to the Azure resource group we created earlier.

The Puppet Bolt provisioner section from the full template above shows that we’ve specified a few settings for our Puppet Bolt provisioner. We specified a Bolt plan, a path for where to look for our modules, and authentication along with privilege escalation information.

With the Packer template created, we can now build our Azure image by running the packer build command and providing the name of the template file.

The build will take a few minutes and should display output similar to that shown below:

The Puppet Bolt plan can be much more complex, but the goal of this post was to showcase how easy it is to integrate the two together.