Building Custom VM Images on Azure
Recently I found myself having to define, and build, some custom virtual machine definitions on Azure. The reason I needed to do this was so that I had some custom Linux and Windows VM images that had certain tools and config pre-configured.
This was a new experience for me, and while I found the documentation and samples pretty useful there’s a lot of copy/pasting and not a lot of scripted, repeatable stuff. I wanted something that was simple to drive, repeatable, and prescriptive.
So, I wrote something for myself.
After reviewing the docs (most of which are listed below) I set about writing a collection of reusable bash scripts, and driving them from a Makefile.
The result is a sample repository on GitHub that allows me to…
- set up the core infrastructure needed to create custom VM image templates and publish them to an Azure Compute Gallery
- define and deploy the various images/versions/templates that Azure requires
- build the custom VM images, using Azure Image Builder, and publish them to Azure Compute Gallery
… so that I can now more easily focus on the actual VM template customisation, and not have to remember the dozen or so Azure CLI commands for setting up the infrastructure or deploying my templates to Azure.
My sample project (note: it’s a SAMPLE…it might not work, it’s not production-ready, and it’s certainly not to be considered “best practice”) can be found on GitHub:
https://github.com/martinpeck/custom-vm-sample-toolkit
If it’s useful to someone other than me…YAY!
If not, well YAY anyway because it helped me.
Oh, and Happy New Year!
Some Bedtime Reading
Here are some useful links/docs if you’re thinking of playing with customer VM images in Azure:
- Azure VM Image Builder overview
- Azure Image Builder Quickstarts - GitHub
- Create a Linux image and distribute it to an Azure Compute Gallery
- Create a Windows image and distribute it to an Azure Compute Gallery
- Example VM Image Template
- Sharing Images in an Azure Gompute Gallery
- Copy Azure Compute Gallery Image Versions between Azure Clouds, Tenants, and Subscriptions
- Azure VM Image Builder networking options