如果要使用自己的 vhd 文件创建 Vm,可以使用 VHD 文件创建 Azure 托管映像,然后使用该映像创建 VM。更多详情请参考here和这里
例如
- 创建 Azure 托管映像
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"images_testimage_name": {
"defaultValue": "testimage1",
"type": "String"
},
"blobUri": {
"defaultValue": "<your vhd file url>",
"type": "String"
},
"location": {
"defaultValue": "",
"type": "String"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Compute/images",
"apiVersion": "2019-07-01",
"name": "[parameters('images_testimage_name')]",
"location": "[parameters('location')]",
"properties": {
"storageProfile": {
"osDisk": {
"osType": "Linux",
"osState": "Generalized",
"diskSizeGB": 30,
"blobUri": "[parameters('blobUri')]",
"caching": "ReadWrite",
"storageAccountType": "Premium_LRS"
},
"dataDisks": [],
"zoneResilient": true
},
"hyperVGeneration": "V1"
}
}
]
}
- 创建虚拟机
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
},
"variables": {},
"resources": [
... other resource
{
"name": "[parameters('virtualMachineName')]",
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2020-06-01",
"location": "[parameters('location')]",
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('virtualMachineSize')]"
},
"storageProfile": {
"osDisk": {
"createOption": "fromImage",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"imageReference": {
"id": "<the resource id of the image you create in step1>"
}
},
... other configurations
}
}
]
}