2017-02-01 7 views
3

コピー機能を使用して、複数のデータディスクを可変容量で複数のVMを展開するテンプレートを作成しようとしています。ドキュメントを正確にフォローしていますが、私の展開はまだ失敗します。 https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-multiple#create-multiple-instances-when-copy-wont-work この問題を解決してください。 azuredeploy.json:Azure RMテンプレート。複数のデータディスクを持つ複数のVM

{ 
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 
    "contentVersion": "1.0.0.0", 
    "parameters": { 
    "adminUsername": { 
     "type": "string", 
     "metadata": { 
     "description": "Username for the Virtual Machine." 
     } 
    }, 
    "adminPassword": { 
     "type": "securestring", 
     "metadata": { 
     "description": "Password for the Virtual Machine." 
     } 
    }, 
    "dnsLabelPrefix": { 
     "type": "string", 
     "metadata": { 
     "description": "Unique DNS Name for the Public IP used to access the Virtual Machine." 
     } 
    }, 
    "windowsOSVersion": { 
     "type": "string", 
     "defaultValue": "2012-R2-Datacenter", 
     "allowedValues": [ 
     "2008-R2-SP1", 
     "2012-Datacenter", 
     "2012-R2-Datacenter" 
     ], 
     "metadata": { 
     "description": "The Windows version for the VM. This will pick a fully patched image of this given Windows version. Allowed values: 2008-R2-SP1, 2012-Datacenter, 2012-R2-Datacenter." 
     } 
    }, 
    "numDataDisks": { 
     "type": "int", 
     "maxValue": 64, 
     "metadata": { 
     "description": "This parameter allows the user to select the number of disks they want" 
     } 
    }, 
    "numberOfInstances": { 
     "type": "int", 
     "defaultValue": 2, 
     "metadata": { 
     "description": "Number of VMs to deploy" 
     } 
    }, 
    "numberOfDataDisksPerVM": { 
     "type": "array", 
     "defaultValue": [ 1, 2 ] 
    }, 
     "_artifactsLocation": { 
      "type": "string" 
     }, 
     "_artifactsLocationSasToken": { 
      "type": "securestring" 
     } 
    }, 
    "variables": { 
    "storageAccountName": "[concat(uniquestring(resourceGroup().id), 'dynamicdisk')]", 
    "sizeOfDataDisksInGB": 100, 
    "diskCaching": "ReadWrite", 
    "imagePublisher": "MicrosoftWindowsServer", 
    "imageOffer": "WindowsServer", 
    "OSDiskName": "osdiskforwindowssimple", 
    "nicName": "dynamicDisksVMNic", 
    "addressPrefix": "10.0.0.0/16", 
    "subnetName": "Subnet", 
    "subnetPrefix": "10.0.0.0/24", 
    "storageAccountType": "Standard_LRS", 
    "publicIPAddressName": "dynamicDisksPublicIP", 
    "publicIPAddressType": "Dynamic", 
    "vmStorageAccountContainerName": "vhds", 
    "vmName": "dynamicDisksVM", 
    "vmSize": "Standard_DS4", 
    "virtualNetworkName": "dynamicDisksVNET", 
    "vnetID": "[resourceId('Microsoft.Network/virtualNetworks',variables('virtualNetworkName'))]", 
    "subnetRef": "[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]", 
    "apiVersion": "2015-06-15", 
    "diskArray": [ 
     { 
     "name": "datadisk1", 
     "lun": 0, 
     "vhd": { 
      "uri": "[concat('http://', variables('storageAccountName'),'.blob.core.windows.net/vhds/', 'datadisk1.vhd')]" 
     }, 
     "createOption": "Empty", 
     "caching": "[variables('diskCaching')]", 
     "diskSizeGB": "[variables('sizeOfDataDisksInGB')]" 
     }, 
     { 
     "name": "datadisk2", 
     "lun": 1, 
     "vhd": { 
      "uri": "[concat('http://', variables('storageAccountName'),'.blob.core.windows.net/vhds/', 'datadisk2.vhd')]" 
     }, 
     "createOption": "Empty", 
     "caching": "[variables('diskCaching')]", 
     "diskSizeGB": "[variables('sizeOfDataDisksInGB')]" 
     }, 
     { 
     "name": "datadisk3", 
     "lun": 2, 
     "vhd": { 
      "uri": "[concat('http://', variables('storageAccountName'),'.blob.core.windows.net/vhds/', 'datadisk3.vhd')]" 
     }, 
     "createOption": "Empty", 
     "caching": "[variables('diskCaching')]", 
     "diskSizeGB": "[variables('sizeOfDataDisksInGB')]" 
     }, 
     { 
     "name": "datadisk4", 
     "lun": 3, 
     "vhd": { 
      "uri": "[concat('http://', variables('storageAccountName'),'.blob.core.windows.net/vhds/', 'datadisk4.vhd')]" 
     }, 
     "createOption": "Empty", 
     "caching": "[variables('diskCaching')]", 
     "diskSizeGB": "[variables('sizeOfDataDisksInGB')]" 
     }, 
    ], 
     "nested-TemplateFolder": "nestedtemplates", 
     "nested-TemplateFileName": "nested-.json", 
     "nested-TemplateParametersFileName": "nested-.parameters.json" 
    }, 
    "resources": [ 
    { 
     "type": "Microsoft.Storage/storageAccounts", 
     "name": "[variables('storageAccountName')]", 
     "apiVersion": "[variables('apiVersion')]", 
     "location": "[resourceGroup().location]", 
     "properties": { 
     "accountType": "[variables('storageAccountType')]" 
     } 
    }, 
    { 
     "apiVersion": "[variables('apiVersion')]", 
     "type": "Microsoft.Network/publicIPAddresses", 
     "name": "[variables('publicIPAddressName')]", 
     "location": "[resourceGroup().location]", 
     "properties": { 
     "publicIPAllocationMethod": "[variables('publicIPAddressType')]", 
     "dnsSettings": { 
      "domainNameLabel": "[parameters('dnsLabelPrefix')]" 
     } 
     } 
    }, 
    { 
     "apiVersion": "[variables('apiVersion')]", 
     "type": "Microsoft.Network/virtualNetworks", 
     "name": "[variables('virtualNetworkName')]", 
     "location": "[resourceGroup().location]", 
     "properties": { 
     "addressSpace": { 
      "addressPrefixes": [ 
      "[variables('addressPrefix')]" 
      ] 
     }, 
     "subnets": [ 
      { 
      "name": "[variables('subnetName')]", 
      "properties": { 
       "addressPrefix": "[variables('subnetPrefix')]" 
      } 
      } 
     ] 
     } 
    }, 
    { 
     "apiVersion": "[variables('apiVersion')]", 
     "type": "Microsoft.Network/networkInterfaces", 
     "name": "[variables('nicName')]", 
     "location": "[resourceGroup().location]", 
     "dependsOn": [ 
     "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]", 
     "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]" 
     ], 
     "properties": { 
     "ipConfigurations": [ 
      { 
      "name": "ipconfig1", 
      "properties": { 
       "privateIPAllocationMethod": "Dynamic", 
       "publicIPAddress": { 
       "id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]" 
       }, 
       "subnet": { 
       "id": "[variables('subnetRef')]" 
       } 
      } 
      } 
     ] 
     } 
    }, 
    { 
     "apiVersion": "[variables('apiVersion')]", 
     "type": "Microsoft.Compute/virtualMachines", 
     "name": "[concat('myvm', copyIndex())]", 
     "copy": { 
     "name": "virtualMachineLoop", 
     "count": "[parameters('numberOfInstances')]" 
     }, 
     "location": "[resourceGroup().location]", 
     "dependsOn": [ 
     "[concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]", 
     "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]" 
     ], 
     "properties": { 
     "hardwareProfile": { 
      "vmSize": "[variables('vmSize')]" 
     }, 
     "osProfile": { 
      "computerName": "[variables('vmName')]", 
      "adminUsername": "[parameters('adminUsername')]", 
      "adminPassword": "[parameters('adminPassword')]" 
     }, 
     "storageProfile": { 
      "imageReference": { 
      "publisher": "[variables('imagePublisher')]", 
      "offer": "[variables('imageOffer')]", 
      "sku": "[parameters('windowsOSVersion')]", 
      "version": "latest" 
      }, 
      "osDisk": { 
      "name": "osdisk", 
      "vhd": { 
       "uri": "[concat('http://',variables('storageAccountName'),'.blob.core.windows.net/',variables('vmStorageAccountContainerName'),'/',variables('OSDiskName'),'.vhd')]" 
      }, 
      "caching": "ReadWrite", 
      "createOption": "FromImage" 
      }, 
      "dataDisks": "[reference(concat('nested-', copyIndex())).outputs.result.value]" 
     }, 
     "networkProfile": { 
      "networkInterfaces": [ 
      { 
       "id": "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName'))]" 
      } 
      ] 
     }, 
     "diagnosticsProfile": { 
      "bootDiagnostics": { 
      "enabled": "true", 
      "storageUri": "[concat('http://',variables('storageAccountName'),'.blob.core.windows.net')]" 
      } 
     } 
     } 
    }, 
    { 
     "name": "[concat('nested-', copyIndex())]", 
     "type": "Microsoft.Resources/deployments", 
     "apiVersion": "2016-09-01", 
     "dependsOn": [], 
     "copy": { 
     "name": "deploycopy", 
     "count": "[parameters('numberOfInstances')]" 
     }, 
     "properties": { 
     "mode": "Incremental", 
     "templateLink": { 
      "uri": "[concat(parameters('_artifactsLocation'), '/', variables('nested-TemplateFolder'), '/', variables('nested-TemplateFileName'), parameters('_artifactsLocationSasToken'))]", 
      "contentVersion": "1.0.0.0" 
     }, 
     "parametersLink": { 
      "uri": "[concat(parameters('_artifactsLocation'), '/', variables('nested-TemplateFolder'), '/', variables('nested-TemplateParametersFileName'), parameters('_artifactsLocationSasToken'))]", 
      "contentVersion": "1.0.0.0" 
     }, 
     "parameters": { 
      "vmName": { "value": "[concat('myvm', copyIndex())]" }, 
      "storageAccountName": { "value": "[variables('storageAccountName')]" }, 
      "numDataDisks": { "value": "[parameters('numberOfDataDisksPerVM')[copyIndex()]]" } 
     } 
     } 
    } 
    ] 
} 

入れ子.json

{ 
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 
    "contentVersion": "1.0.0.0", 
    "parameters": { 
    "vmName": { 
     "type": "string" 
    }, 
    "storageAccountName": { 
     "type": "string" 
    }, 
    "numDataDisks": { 
     "type": "int", 
     "maxValue": 16, 
     "metadata": { 
     "description": "This parameter allows the user to select the number of disks they want" 
     } 
    } 
    }, 
    "variables": { 
    "diskArray": [ 
     { 
     "name": "datadisk1", 
     "lun": 0, 
     "vhd": { 
      "uri": "[concat('http://', variables('storageAccountName'),'.blob.core.windows.net/vhds/', 'datadisk1.vhd')]" 
     }, 
     "createOption": "Empty", 
     "caching": "[variables('diskCaching')]", 
     "diskSizeGB": "[variables('sizeOfDataDisksInGB')]" 
     }, 
     { 
     "name": "datadisk2", 
     "lun": 1, 
     "vhd": { 
      "uri": "[concat('http://', variables('storageAccountName'),'.blob.core.windows.net/vhds/', 'datadisk2.vhd')]" 
     }, 
     "createOption": "Empty", 
     "caching": "[variables('diskCaching')]", 
     "diskSizeGB": "[variables('sizeOfDataDisksInGB')]" 
     }, 
     { 
     "name": "datadisk3", 
     "lun": 2, 
     "vhd": { 
      "uri": "[concat('http://', variables('storageAccountName'),'.blob.core.windows.net/vhds/', 'datadisk3.vhd')]" 
     }, 
     "createOption": "Empty", 
     "caching": "[variables('diskCaching')]", 
     "diskSizeGB": "[variables('sizeOfDataDisksInGB')]" 
     }, 
     { 
     "name": "datadisk4", 
     "lun": 3, 
     "vhd": { 
      "uri": "[concat('http://', variables('storageAccountName'),'.blob.core.windows.net/vhds/', 'datadisk4.vhd')]" 
     }, 
     "createOption": "Empty", 
     "caching": "[variables('diskCaching')]", 
     "diskSizeGB": "[variables('sizeOfDataDisksInGB')]" 
     } 
    ] 
    }, 
    "resources": [ 
    ], 
    "outputs": { 
    "result": { 
     "type": "array", 
     "value": "[take(variables('diskArray'),parameters('numDataDisks'))]" 
    } 
    } 
} 

答えて

2

だから、アスカーはのは、いくつかのVMのとディスクの動的な量を持つようにしたいので、私は、ネストされたテンプレート・アプローチを使用する必要がありました。何らかの理由で整形休憩のために私はそう、ここでそれを貼り付ける場合:

https://github.com/4c74356b41/armotron/blob/master/ml-vm-ml-dd.json

この全体のことは今意味がありません。今すぐコピーしてください:
https://github.com/rjmax/Build2017/blob/master/Act1.TemplateEnhancements/Chapter02.PropertyCopies.json

+0

あなたのアプローチは良いです!ありがとうございました!はるかに優れた解決策がある場合、Azureのドキュメントにはあまりにも複雑な例はありませんでした。 https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-multiple#create-multiple-instances-when-copy-wont-work – WinBoss

+0

更新:マークしましたこれは早々に解決策として(申し訳ありません)。私は対話的にパラメータを指定して、このテンプレートの追加ディスクの数を増やしたいと思います。 – WinBoss

+0

それは私がやろうとしていたことですが、それはうまくいきません。 myvm0とmyvm1は同じデータディスク名/ URIを使用しようとしています https://ghostbin.com/paste/bok5t – WinBoss

関連する問題