如何为azure虚拟机创建数据磁盘?

时间:2017-03-02 07:13:06

标签: json powershell azure msdn

我在使用以下json模板创建虚拟机时向虚拟机添加了多个数据磁盘。

"variables": {  
"diskArray": [  
{  
"name": "datadisk1",
"lun": 0,   
"vhd": {  
"uri": "[concat('http://', variables('storageAccountName'),'.blob.core.windows.net/vhds/','datadisk1.vhd')]"  
        },  
        "createOption": "Empty",    
        "caching": "ReadWrite",    
        "diskSizeGB": 300    
      },    
      {    
        "name": "datadisk2",
        "lun": 1,
        "vhd": {
          "uri": "[concat('http://', variables('storageAccountName'),'.blob.core.windows.net/vhds/', 'datadisk2.vhd')]"    
        },  
        "createOption": "Empty",    
        "caching": "ReadWrite",    
        "diskSizeGB": 200  
      },  
      {   
        "name": "datadisk3",  
        "lun": 2,  
        "vhd": {  
          "uri": "[concat('http://', variables('storageAccountName'),'.blob.core.windows.net/vhds/', 'datadisk3.vhd')]"  
        },  
        "createOption": "Empty",  
        "caching": "ReadWrite",  
        "diskSizeGB": 100  
      }  
]    
  },    
.....    
.....   
"resources": [  
    {  
      "apiVersion": "2015-06-15",  
      "type": "Microsoft.Compute/virtualMachines",  
      "name": "[concat(parameters('VmPrefix'), copyindex(1))]",  
      "copy": {  
        "name": "Datanode",  
        "count": "[variables('vmcount')]"  
      },  
      "location": "[resourceGroup().location]",  
      "properties": {  
         ......  
         ......  
        "storageProfile": {  
          "imageReference": {  
            ........  
          },  
          "dataDisks":   "[take(variables('diskArray'),parameters('numDataDisks'))]",  
          "osDisk": {  
            .......  
          }  
        }  
    }  
}  
]  

此代码在创建单个虚拟机时工作正常,但在创建多个虚拟机时,计算机无法创建。这是因为为第一台机器的datadisks创建的vhd与其他机器相同。

有没有办法创建一个名称不同的vhd? 尝试传递复制索引,但不起作用。

1 个答案:

答案 0 :(得分:2)

当然有,我会粘贴到模板的链接,并解释它是如何工作的。这是link

因此,为了做到这一点,你必须将copyindex(或类似的东西)添加到磁盘名称中,其中一种方法是使用嵌套模板,该模板将返回带有磁盘的对象,并且在调用模板时,您可以使用copyindex作为参数。

This is您在其中创建嵌套部署以创建磁盘对象 并here使用输出创建磁盘。

相关问题