Using a Packer image with Terraform
Now that we have generated a custom VM image, we will provision a new VM based on this new image. For the provisioning of this VM, we will continue to use IaC practices using Terraform from HashiCorp.
To do this, we will take the Terraform script created in Chapter 2, Provisioning Cloud Infrastructure with Terraform,, and modify it to use the custom image.
In the compute.tf
script, add the following block of data, which will point to the VM image that we generated with Packer in the last section:
## GET THE CUSTOM IMAGE CREATED BY PACKER data "azurerm_image" "customngnix" { name = "linuxWeb-0.0.1" resource_group_name = "rg_images" }
In this code, we add a block of azurerm_image
Terraform data that allows us to retrieve the properties of a VM image in Azure, in which we specify the name
property with name of the custom image, and the resource_group_name
property with the resource group of the image...