none
ARM Template Example - Managed Disks RRS feed

  • Question

  • Anyone have an ARM Template example leveraging the new Managed Disks. I think I have some of it but wanted to look at a working example to compare.

    Thank you.

    Thursday, February 9, 2017 4:14 PM

Answers

  • Found one.

    https://github.com/Azure-Samples/resources-dotnet-deploy-virtual-machine-with-managed-disks-using-arm-template/blob/master/ARMTemplate/TemplateValue.json


    For anyone that is interested.

    If using Availability Sets you will need to create one that is managed like below: (Taking note of the Properties and SKU fields)

    {
        "type": "Microsoft.Compute/availabilitySets",
        "name": "myAvailabilitySet",
        "apiVersion": "[providers('Microsoft.Compute', 'availabilitySets').apiVersions[0]]",
        "location": "[resourceGroup().location]",
        "properties": {
            "platformUpdateDomainCount": 5,
            "platformFaultDomainCount": 2
        },
        "sku": {
            "name": "Aligned"
        }
    }

    Here is the resource to create managed disks: (This is for DataDisks.  The OSDisk is created in the VirtualMachine resource.

    {
        "type": "Microsoft.Compute/disks",
        "name": "dataDisk1",
        "apiVersion": "2016-04-30-preview",
        "location": "[resourceGroup().location]",
        "properties": {
            "creationData": {
                "createOption": "Empty"
            },
            "accountType": "Premium_LRS",
            "diskSizeGB": 128
        }
    }

    Then to tie it all together in the VM Resource:

    I am just showing the relevant parts of the VM resource pertaining to managed disks.

    The OS Disk is created as a managed disk when you specify the managed disk property under the osDisk field.

    {
        "type": "Microsoft.Compute/virtualMachines",
        "name": "myVMName",
        "location": "[resourceGroup().location]",
        "apiVersion": "2016-04-30-preview",
        "dependsOn": [
            "Microsoft.Compute/disks/dataDisk1"
         ],
         ...
                  
         "storageProfile": {
            "imageReference": {
                "publisher": "MicrosoftWindowsServer",
                "offer": "WindowsServer",
                "sku": "2012-R2-Datacenter",
                "version": "latest"
            },
            "osDisk": {
                "osType": "Windows",
                "caching": "ReadWrite",
                "createOption": "FromImage",
                "name": "OSDisk",
                "managedDisk": {
                    "storageAccountType": "Premium_LRS"
                }
            },
            "dataDisks": [{
                "lun": 0,
                "managedDisk": {
                    "id": "[resourceId('Microsoft.Compute/disks', 'dataDisk1')]"
                },
                    "caching": "None",
                    "createOption": "Attach"
            }]
        }
    }

    Hopefully this helps anyone else looking to use managed disks with their ARM templates.

    Marco

    • Marked as answer by MCrank Thursday, February 9, 2017 6:48 PM
    • Edited by MCrank Thursday, February 9, 2017 8:28 PM
    Thursday, February 9, 2017 6:47 PM

All replies

  • Found one.

    https://github.com/Azure-Samples/resources-dotnet-deploy-virtual-machine-with-managed-disks-using-arm-template/blob/master/ARMTemplate/TemplateValue.json


    For anyone that is interested.

    If using Availability Sets you will need to create one that is managed like below: (Taking note of the Properties and SKU fields)

    {
        "type": "Microsoft.Compute/availabilitySets",
        "name": "myAvailabilitySet",
        "apiVersion": "[providers('Microsoft.Compute', 'availabilitySets').apiVersions[0]]",
        "location": "[resourceGroup().location]",
        "properties": {
            "platformUpdateDomainCount": 5,
            "platformFaultDomainCount": 2
        },
        "sku": {
            "name": "Aligned"
        }
    }

    Here is the resource to create managed disks: (This is for DataDisks.  The OSDisk is created in the VirtualMachine resource.

    {
        "type": "Microsoft.Compute/disks",
        "name": "dataDisk1",
        "apiVersion": "2016-04-30-preview",
        "location": "[resourceGroup().location]",
        "properties": {
            "creationData": {
                "createOption": "Empty"
            },
            "accountType": "Premium_LRS",
            "diskSizeGB": 128
        }
    }

    Then to tie it all together in the VM Resource:

    I am just showing the relevant parts of the VM resource pertaining to managed disks.

    The OS Disk is created as a managed disk when you specify the managed disk property under the osDisk field.

    {
        "type": "Microsoft.Compute/virtualMachines",
        "name": "myVMName",
        "location": "[resourceGroup().location]",
        "apiVersion": "2016-04-30-preview",
        "dependsOn": [
            "Microsoft.Compute/disks/dataDisk1"
         ],
         ...
                  
         "storageProfile": {
            "imageReference": {
                "publisher": "MicrosoftWindowsServer",
                "offer": "WindowsServer",
                "sku": "2012-R2-Datacenter",
                "version": "latest"
            },
            "osDisk": {
                "osType": "Windows",
                "caching": "ReadWrite",
                "createOption": "FromImage",
                "name": "OSDisk",
                "managedDisk": {
                    "storageAccountType": "Premium_LRS"
                }
            },
            "dataDisks": [{
                "lun": 0,
                "managedDisk": {
                    "id": "[resourceId('Microsoft.Compute/disks', 'dataDisk1')]"
                },
                    "caching": "None",
                    "createOption": "Attach"
            }]
        }
    }

    Hopefully this helps anyone else looking to use managed disks with their ARM templates.

    Marco

    • Marked as answer by MCrank Thursday, February 9, 2017 6:48 PM
    • Edited by MCrank Thursday, February 9, 2017 8:28 PM
    Thursday, February 9, 2017 6:47 PM
  • I've never seen this particular way of assigning resource APIs, does it just pull the latest from the schema?

        "apiVersion": "[providers('Microsoft.Compute', 'availabilitySets').apiVersions[0]]",
    Thursday, February 16, 2017 11:32 AM
  • Hey Will.  It does "for the most part".  I have come across times where it fails template validation in particular the Microsoft.Compute/disks resource will actually fail.  I dumped it as an output in my template and it was pulling back a version from the future.  Something like 03/30/2017 or something like that.  At the time there were only two API versions the one posted above and this "future" version that would fail.  Most other resources work though.  Not sure why Microsoft just doesn't include a "latest" option for that.

    Hope that helps.

    Marco

    Saturday, February 18, 2017 12:54 AM
  • Just to add, you do not have to create the data disk resource separately, you can specify all properties within the VM storage profile and it will create it; using it here in a VM resource creation loop....

    {
          "type": "Microsoft.Compute/virtualMachines",
          "name": "[concat(variables('vmNamePrefix'), copyIndex())]",
          "apiVersion": "[variables('computeApi')]",
          "location": "[resourceGroup().location]",
          "copy": {
            "name": "virtualMachineLoop",
            "count": "[parameters('vmCount')]"
          },
          "dependsOn": [
            "[resourceId('Microsoft.Compute/availabilitySets', variables('availabilitySetName'))]",
            "nicLoop"
          ],
          "properties": {
            "availabilitySet": {
              "id": "[resourceId('Microsoft.Compute/availabilitySets', variables('availabilitySetName'))]"
            },
            "hardwareProfile": {
              "vmSize": "[parameters('vmSize')]"
            },
            "osProfile": {
              "computerName": "[concat(variables('vmNamePrefix'), copyIndex())]",
              "adminUsername": "[parameters('domainAdminUsername')]",
              "adminPassword": "[parameters('domainAdminPassword')]",
              "windowsConfiguration": {
                "enableAutomaticUpdates": false
              }
            },
            "storageProfile": {
              "imageReference": "[variables('imageReference')]",
              "osDisk": {
                "name": "[concat(variables('vmNamePrefixInfix'), copyIndex(), '-osdisk')]",
                "createOption": "FromImage",
                "caching": "ReadWrite",
                "managedDisk": {
                  "storageAccountType": "[variables('storageAccountType')]"
                }
              },
              "dataDisks": [
                {
                  "lun": 1,
                  "name": "[concat(variables('vmNamePrefixInfix'), copyindex(), '-data0')]",
                  "createOption": "Empty",
                  "caching": "None",
                  "diskSizeGB": "[parameters('vmDataDiskSize')]",
                  "managedDisk": {
                    "storageAccountType": "[variables('storageAccountType')]"
                  }
                }
              ]
            },
            "networkProfile": {
              "networkInterfaces": [
                {
                  "id": "[resourceId('Microsoft.Network/networkInterfaces',concat(variables('vmNamePrefixInfix'), copyIndex(), '-nic0'))]"
                }
              ]
            }
          }

    Thursday, February 23, 2017 6:37 PM
  • Hi there,

    Let's try this https://azure.microsoft.com/en-us/resources/templates/

    https://vincentlauzon.com/2017/02/21/migrating-from-unmanaged-to-managed-disks/


    Tariq Younas

    Thursday, February 23, 2017 7:58 PM
  • How do you create template that can create managed or unmanaged OS disk based on the "managed disk" parameter that user may have selected. 

        "osDisk": {
                            "name": "[if(equals(parameters('managedDisk'),'false'),variables('OSDiskName'),json('null'))]",
                            "vhd": {
                                "uri": "[concat(reference('Microsoft.Resources/deployments/SettingUpStorageAccount', '2015-01-01').outputs.storageAccountId.value, 'vhds/osdisk', uniqueString(deployment().name), '.vhd')]"
                            },
                            "caching": "[if(equals(parameters('managedDisk'),'false'),'ReadWrite',json('null'))]", 
                            "createOption": "FromImage",
                            "managedDisk": "[if(equals(parameters('managedDisk'),'true'),variables('managedDiskVar'),json('null'))]"
                        }

    I tried above in my template but it does not work as expected. can someone help?

    Saturday, August 19, 2017 5:31 AM
  • Great answer
    Saturday, August 19, 2017 5:32 AM