Photo by Hal Gatewood on Unsplash

How to use Packer to build a Windows Server Image for Azure

Guillermo Musumeci

--

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.

1. Prerequisites

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.

1.1. Packer

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.

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:

az login

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>

--

--

Guillermo Musumeci

Certified AWS, Azure & GCP Architect | HashiCorp Ambassador | Terraform SME | KopiCloud Founder | ex-AWS | Entrepreneur | Book Author | Husband & Dad of ✌