Packer is an open-source tool used to create virtual machine templates from a .json file.
In this story, we will learn how to use Packer to define and build custom images in Azure, and then use this image to build a Windows virtual machine using Terraform.
To create our own custom virtual machine images in Azure with Packer, we will need Packer (pretty obvious) and a couple of resources in Azure.
Packer is available to download at https://www.packer.io as a single binary file.
We can download Packer binary for macOS, Linux, or Windows from the Packer web site
We can install on macOS using Homebrew by executing brew install packer
We can install on Linux using apt-get by executing apt-get install packer
1.2. How to Install Packer in Windows?
The process is very simple.
- Download the .zip file from https://www.packer.io/downloads.html
- Extract the .ZIP file to a folder
- Add the folder to the path variable
1.3. Azure Prerequisites
To create an Azure Virtual Machine Image, we need a Service Principal (also known as SPN) and a Resource Group.
First, we need to authenticate to Azure. To authenticate using Azure CLI, we type:
The process will launch the browser and after the authentication is complete we are ready to go.
We will use the following command to get the list of Azure subscriptions:
az account list --output table
We can select the subscription using the following command (both subscription id and subscription name are accepted):
az account set --subscription <Azure-SubscriptionId>