Photo by Tadas Sar on Unsplash

Create a Virtual Machine and Attach an osDisk Snapshot using ARM Template

Azure Resource Manager (ARM)| Snapshot | Azure CLI

βš— Kevin Summersill πŸ”‹
5 min readJun 21, 2021

--

Have you ever had a need to replicate a Virtual Machine using an Existing Operating System (OS) Disk on Azure? Well, i know i did. So this article will explain how to do this.

Assumptions:

  • Assumes you already created a Virtual Network (VNet), Network Security Groups (NSGs), and Subnet to associate to the below Virtual Machine.
  • Assumes you have Azure CLI Installed
  • Assumes you have the capability to run ARM Templates

Step 1. Creating the Snapshot

You can create a snapshot with easy by using the Azure CLI commands. I have written a powershell script that will do just this:

# Must already have a Virtual Machine with an OS Disk prior to running the script. 
$resourceGroup = "<your resource group name>"
$virtualMachineName = "<your virtual machine name>"
$snapshotName = "<name of your new snapshot>"
Write-Output "Getting OS Disk ID for Virtual Machine..."
$osDiskId = az vm list -g $resourceGroup --query "[?name == '$virtualMachineName'].storageProfile.osDisk.managedDisk.id" --output tsv
Write-Output…

--

--

βš— Kevin Summersill πŸ”‹

Enterprise Solution Architect | Certified K8s Administrator/Developer βš“ | SAFe SPC | Cert Terraform | AWS Solutions Architect | Dev*Ops/GitOps Engineer πŸ”₯