所以我設法實現了它。可能不是最優雅的,但它的作品。儘管Microsoft seem to suggest using a top-level resource用於創建數據盤,但我不明白這是如何工作的,因爲我不知道如何在DependsOn []中使用copy [],如果您要在同一模板中創建磁盤和虛擬機,他們會嘗試並同時部署。
對於那些可能有興趣,這裏是我的解決方案:
首先,我用觸發PowerShell的New-AzureRmResourceDeployment
的模板。我沒有使用參數文件。參數在PS中生成。
$RG = "ResourceGroup where VM resides"
$Disks = @(
@{name = "datadisk-001";diskSizeGB = "256";lun = 0}
@{name = "datadisk-002";diskSizeGB = "256";lun = 1}
@{name = "datadisk-003";diskSizeGB = "512";lun = 2}
@{name = "datadisk-004";diskSizeGB = "512";lun = 3}
@{name = "datadisk-005";diskSizeGB = "512";lun = 4}
@{name = "datadisk-006";diskSizeGB = "512";lun = 5}
)
$params = @{
diskConfig = $disks
storageAccounttype = "Standard_LRS"
vmName = "AUCADN102007006"
}
New-AzureRmResourceGroupDeployment -Name "SomeDeploymentName" `
-ResourceGroupName $RG `
-Mode Incremental `
-DeploymentDebugLogLevel All `
-TemplateFile C:\Temp\DiskTest.json" `
-Verbose `
@params
模板本身被嚴重削減,實際上並沒有創建虛擬機。引用的VM需要存在。我已儘可能多地取出。
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"type": "string"
},
"diskConfig": {
"type": "array"
},
"storageAccountType": {
"type": "string",
"defaultValue": "Standard_LRS",
"allowedValues": [
"Standard_LRS",
"Premium_LRS"
],
"metadata": {
"description": "Type of disk"
}
}
},
"variables": {
"vmSize": "Standard_DS4_v2",
"sharedVariables": {
"storageAccountType": "[parameters('storageAccountType')]"
}
},
"resources": [
{
"apiVersion": "2017-03-30",
"type": "Microsoft.Compute/virtualMachines",
"name": "[parameters('vmName')]",
"location": "[resourceGroup().location]",
"dependsOn": [
],
"properties": {
"storageProfile": {
"copy": [
{
"name": "dataDisks",
"count": "[length(parameters('diskConfig'))]",
"input": {
"name": "[concat(parameters('vmName'),'-',parameters('diskConfig')[CopyIndex('dataDisks')].name)]",
"diskSizeGB": "[parameters('diskConfig')[CopyIndex('dataDisks')].diskSizeGB]",
"lun": "[parameters('diskConfig')[copyIndex('dataDisks')].lun]",
"createOption": "Empty",
"managedDisk": {
"storageAccountType": "[variables('sharedVariables').storageAccountType]"
}
}
}
]
}
}
}
],
"outputs": {
"arrayOutput1": {
"type": "array",
"value": "[parameters('diskConfig')]"
},
"arrayCount": {
"type": "int",
"value": "[length(parameters('diskConfig'))]"
}
}
}
由於this帖子裏筆者演示了使用索引:
"properties": {
"accountType": " [parameters('storageAccountList')[copyIndex()].storageAccountType]"
}
注copyIndex()是如何在[]
TODO:做一些與$Disks
更好,使用PS創建哈希表或在模板內創建哈希表。
HTH
你能寫出如何確切的磁盤需要不同?什麼是斷點?什麼需要不同? – 4c74356b41
更新了磁盤配置示例。謝謝 – woter324
我想我知道如何做到這一點,但現在我對事件感到有點不知所措。我會在大約10個小時內回到這個。如果我忘了,請在這裏平息我 – 4c74356b41