Create Managed Disk VM (ARM Template)

Azure Managed Disk is the way we can deploy VMs disks without using storage account. In previous(Unmanaged) disks before we create a VM (ARM) we need to create a storage account to store those VMs disks. Managing storage account may be a difficult when it comes to large deployments. By introducing managed disk we can eliminate two limitations that face in storage accounts.

  • Single subscription has a soft limit of 200 storage accounts.
  • Azure recommend not to store more than 40 disks in single storage account due to IOPS limit for storage account.
    For standard storage accounts: A standard storage account has a maximum total request rate of 20,000 IOPS. The total IOPS across all of your virtual machine disks in a standard storage account should not exceed this limit.You can roughly calculate the number of highly utilized disks supported by a single standard storage account based on the request rate limit. For example, for a Basic Tier VM, the maximum number of highly utilized disks is about 66 (20,000/300 IOPS per disk), and for a Standard Tier VM, it is about 40 (20,000/500 IOPS per disk)” 

As mentioned above we don’t have to worry about the storage account anymore when we deploy through managed disks.Azure fabric will take care of the scalability of the disk. One other advantage of using Managed Disk was when we deploy VMSS(Virtual Machine Scale Sets) we can create 1000 of VMs and easy to manage the disks of the scale set VMs.

The other advantage of using managed disk was better reliability for Availability Sets

As you see above when we used unmaaged disk even the VMs are in the availability sets but the storage disk are in one storage unit, so its single point of failure. We can eliminate this using managed disk when we use managed disk with availability feature enable Azure fabric stored each VMs disk in availability set in different storage units.We can enable Managed disk availability set as follows.

NOTE- Make Sure you select Yes(Aligned) in Use Managed Disk

Now lets see how we can deploy managed disk using ARM Template,In this I wont explain the structure and how we deployed the VM and resources in ARM template.I’ll be explaining the storage configuration in the template.

Following is the code snippet use to deeply unmanaged disks.

        "storageProfile": {
          "imageReference": {
            "publisher": "[variables('webImagePublisher')]",
            "offer": "[variables('webImageOffer')]",
            "sku": "[parameters('SvrWindowsOSVersion')]",
            "version": "latest"
          },
          "osDisk": {
            "name": "web01OSDisk",
            "vhd": {
              "uri": "[concat('https://', parameters('k2prostorageName'), '.blob.core.windows.net/', variables('StorageAccountContainerName'), '/', variables('webOSDiskName'), copyIndex(), '.vhd')]"
            },
            "caching": "ReadWrite",
            "createOption": "FromImage"
          }
        },

In above code snippet in osDisk we have to specify the uri of the storage account.This URI leads to the storage account we have to store the disk.

Now lets see the code snippet of a managed disk as follows.

NOTE– When we use managed disk make sure you use the latest API version for the VM resource as of this writing its ( “apiVersion”: “2016-04-30-preview”)

      "name": "[parameters('VMName')]",
      "type": "Microsoft.Compute/virtualMachines",
      "location": "[resourceGroup().location]",
      "apiVersion": "2016-04-30-preview",

        "storageProfile": {
          "imageReference": {
            "publisher": "[variables('ManagedDiskImagePublisher')]",
            "offer": "[variables('ManagedDiskImageOffer')]",
            "sku": "[parameters('ManagedDiskWindowsOSVersion')]",
            "version": "latest"
          },
          "osDisk": {
            "createOption": "FromImage"
          },
          "dataDisks": [
            {
              "createOption": "Empty",
              "lun": 0,
              "diskSizeGB": "1023",
              "caching": "None"
            }
          ]
        },

If you compare these two code snippet you will see a difference, In managed disk we don’t want to specify a uri for the storage account because Azure fabric take care of the storage path.Even we can add a data disk and we don’t want to specify the storage account URI.