Building VM images in Azure using Packer and Deploying with Terraform, in an Azure DevOps pipeline!

Jack Roper
CodeX
Published in
5 min readJun 8, 2021

--

Photo by Blake Connally on Unsplash

Deploying a VM in Azure is all well and good, but what about the base configuration of the VM itself? That's where Packer comes in, enabling a custom image to be created and configured with server roles, applications, packages, etc. as required. That custom image can then be used to build your virtual machines. Creating it using Packer enables the benefits of infrastructure as code, which can be source control managed and tracked.

In this article, I’ll show how to create a Packer image that simply has the AD DS and DNS server roles added to a base Windows 2019 datacenter image from the Azure Marketplace. This image is then used to deploy a VM using Terraform.

NOTE: This blog post describes how to use Packer with .json template files. It is now recommended to use .hcl files for your templates. If you want to use .json files with Azure DevOps and Terraform, please read on! If not I have a separate post showing how to configure with .hcl files here.

Creating the Packer Image

--

--

Jack Roper
CodeX
Writer for

A blog about DevOps & Cloud Tech. Specializing in Terraform, Kubernetes, Azure & Azure DevOps! ☁️