This repo is based on the Packer and Terraform code used in the DevOps Lab episode "Automating Azure Image Pipelines with HCP Packer". That original repo has been split into two separate repos, this one for the image workflow and a second repo for deploying HashiCafe to Azure. Both repos have been enhanced to leverage dynamic Azure credentials using HCP Vault, which was originally configured by following the directions in the learn Azure Secrets Engine tutorial. For this repo a Github Actions pipeline has been configured so that updates to the repo will trigger image updates. Since the image updates take some time (~13minutes for each) the actual image that gets updated is controlled by updating the reference in the pipeline yaml file (so you can build the base image version before a demo and perhaps the child image during the demo - but have other things to talk about...)
Below are the original instructions for updates required for Azure/HCP Packer to enable them to work with this repo.
These configurations demonstrate using Packer to build customized Azure VM images which are published to the HCP Packer hosted image registry and consumed by a Terraform provisioning workflow. Image ancestry tracking in HCP Packer is also demonstrated by building a parent/child image pipeline.
- An Azure subscription with an existing Resource Group where builds will occur and images will be stored, including a Compute Gallery pre-populated as described in the Notes section below
- Azure CLI
- An HCP Packer image registry (free for up to 10 images)
- Packer 1.7.7 or newer
- Terraform 1.0 or newer
hcp-packer-ubuntu20
- the base or "parent" imagehcp-packer-ubuntu20-nginx
- "child" image which derives from the base to add Nginxhashicafe-webserver
- a Terraform configuration to deploy the image as a simple webapp
The Packer builds will create a managed image and also publish to an Azure compute gallery, which must be located in the same Resource Group as your images.
The compute gallery must have VM image definitions pre-created with the following settings:
- VM image definition name:
ubuntu20-base
andubuntu20-nginx
- OS type: Linux
- VM generation: Gen2
- Publisher/Offer/SKU: any valid values are fine
Optionally, you can remove the destination_shared_image_gallery block from the Packer builds; it's included to demonstrate the capability but isn't critical to the workflow.
- Sign in to your Azure account with
az login
. - Make a copy of the
packer.auto.pkrvars.hcl.example
andterraform.auto.tfvars.example
files without the.example
suffix, and fill in your desired values. See each variables file for descriptions. - Run the
hcp-packer-ubuntu20
build, then in HCP Packer assign the new iteration in the ubuntu20-base bucket to a channel named "development". - Run the
hcp-packer-ubuntu20-nginx
build, then assign the new iteration in the ubuntu20-nginx bucket to a channel named "development". - Run the
hashicafe-webserver
Terraform configuration.