In this blog post, I’ll show how to use a Packer file written in HCL, to create an image in Azure. We’ll be using an Azure DevOps pipeline to deploy the image. That resulting image can then be used with Terraform to deploy VMs!

Write Packer templates using HCL

As of v1.5 Packer supports Hashicorp Configuration Language, the language used by Terraform, which is much more human-readable to write and understand than JSON which was used prior to v1.5. Packer is at version 1.7.3 at the time of writing.

It is recommended to migrate away from using .json files for your Packer templates. You can automatically upgrade your old Packer json files to HCL as of v1.6.2 using the hcl2_upgrade command.

packer hcl2_upgrade filename.json

I have another post describing how to use .json templates with the Azure DevOps pipeline here, if you don’t want to upgrade your templates first to hcl.

Packer HCL template

My packer template below installs a plugin to perform windows updates on the image and then generalises it ready for VMs to use it as the source.

#azure-devops #terraform #ci-cd-pipeline #hashicorp-packer #azure

Creating VM Images in Azure with Packer HCL, using Azure DevOps Pipelines.
2.00 GEEK