Minimum Viable Template: Add Data Disks to a VM

This post is part of a series of posts showing how to create a “minimum viable ARM template” and how to modify it to suit various scenarios. To see the full list of posts in this series, see this page: https://negatblog.wordpress.com/minimum-viable-arm-templates/.

In data-intensive scenarios, we may need more disks attached to our virtual machines. Let’s see how to add “data disks” to our minimum viable VM template. We begin from the “minimum-viable-vm” branch (https://github.com/gatneil/MinimumViableArmTemplate/blob/minimum-viable-vm/azuredeploy.json) and end at the “vm-with-data-disk” branch (https://github.com/gatneil/MinimumViableArmTemplate/blob/vm-with-data-disk/azuredeploy.json). The diff is below.

The diff for this scenario is fairly simple. In the virtual machine “storageProfile”, we simply specify a list of datadisk objects. In this case, we specify the disks to be empty (as opposed to pre-populated) and of size 100GB. The maximum limit for disk size used to be 1024GB, but the limit changes over time. For more information, see this blog post: https://azure.microsoft.com/blog/azure-introduces-new-disks-sizes-up-to-4tb/. One interesting property of the data disks is the “lun” property. This property specifies the slot number of the data disk when it is attached to the VM. I’m not very familiar with this property (e.g. I’m not sure if the ordering of luns in the template corresponds to the ordering of the drive paths in the guest VM), but we must provide a different lun for each data disk attached to the VM:

...
     {
       "type": "Microsoft.Compute/virtualMachines",
       "apiVersion": "2020-06-01",
       "name": "myVM",
       "location": "[resourceGroup().location]",
       "dependsOn": [
         "[resourceId('Microsoft.Network/networkInterfaces', 'myNic')]"
       ],
       "properties": {
         "hardwareProfile": {
           "vmSize": "Standard_D2_v4"
         },
         "storageProfile": {
           "imageReference": {
             "publisher": "Canonical",
             "offer": "UbuntuServer",
             "sku": "18.04-LTS",
             "version": "latest"

-          }
+          },
+          "dataDisks": [
+            {
+              "diskSizeGB": "100",
+              "lun": 0,
+              "createOption": "Empty"
+            },
+            {
+              "diskSizeGB": "100",
+              "lun": 1,
+              "createOption": "Empty"
+            }
+          ]

         },
         "networkProfile": {
           "networkInterfaces": [
             {
               "id": "[resourceId('Microsoft.Network/networkInterfaces', 'myNic')]"
             }
           ]
         },
         "osProfile": {
           "computerName": "myVM",
           "adminUsername": "[parameters('adminUsername')]",
           "adminPassword": "[parameters('adminPassword')]"
         }
       }
     }
...

Leave a comment