Search code examples
azureazure-virtual-machineazure-deploymentvhdazure-rm-template

how to create VM with Json arm template using define VHD (or disk,snapshot)?


The question in the title: "how to create VM with Json arm template using define VHD (or disk,snapshot) in azure?" Thanks for your help!


Solution

  • You can create the vm from VHD file through the template. The steps are that you can upload the VHD file to an Azure storage account and create a managed disk from the VHD file. Then attach it to the VM.

    Create the managed disk from the VHD file:

    {
          "type": "Microsoft.Compute/disks",
          "apiVersion": "2018-04-01",
          "name": "[variables('diskName')]",
          "location": "[parameters('location')]",
          "properties": {
            "creationData": {
              "createOption": "Import",
              "sourceUri": "[parameters('osDiskVhdUri')]"
            },
            "osType": "[parameters('osType')]"
          }
        }
    

    Attach the managed disk to the VM:

    "storageProfile": {
              "osDisk": {
                "osType": "[parameters('osType')]",
                "createOption": "Attach",
                "managedDisk": {
                  "id": "[resourceId('Microsoft.Compute/disks', variables('diskName'))]"
                }
              }
            }
    

    You can get the whole template here.