簡體   English   中英

具有VM和子網的Azure ARM模板

[英]Azure ARM Template with VM and subnet

我有一個名為network-rg的資源組,其中包含一個虛擬網絡。 我正在嘗試在新資源組vm-rg中部署虛擬機。 VM應該連接到network-rg中的vnet上的新子網。 我正在將一個ARM模板與子網和VM一起使用,並部署到vm-rg。 當其vnet位於部署的主要/默認組之外的另一個資源組中時,如何在ARM模板中指定子網?

我需要使用資源組明確引用vnet。 這類似於網絡接口部署在其ipConfigurations屬性列表中引用子網ID的方式:

  "apiVersion": "2015-05-01-preview",
  "type": "Microsoft.Network/networkInterfaces",
  "name": "[parameters('nicName')]",
  "location": "[parameters('location')]",
  "properties": {
      "ipConfigurations": [{
          "name": "ipconfig1",
          "properties": {
              "subnet": {
                  "id": "[variables('subnet1Ref')]"
              }
          }
      }]
   }

當您使用資源創建新的資源組時,似乎無法在一個模板的另一個資源組中創建子網。 沒有屬性可以引用另一個組中的Vnet。

如果您真的想在一個模板的另一個組中創建一個新的子網,則可以查看鏈接和嵌套的模板 希望這會幫助你。

您將需要在下面添加變量(引用參數文件的模板中的資源)示例:

在main.JSON文件中:

{
    "name": "[parameters('networkInterfaceName')]",
    "type": "Microsoft.Network/networkInterfaces",
    "apiVersion": "2018-04-01",
    "location": "[parameters('location')]",
    "dependsOn": [
      "[concat('Microsoft.Network/publicIpAddresses/', parameters('publicIpAddressName'))]"
    ],
    "properties": {
      "ipConfigurations": [
        {
          "name": "ipconfig1",
          "properties": {
            "subnet": {
              "id": "[variables('subnetRef')]"
            },
            "privateIPAllocationMethod": "Dynamic",
            "publicIpAddress": {
              "id": "[resourceId(parameters('resourceGroupName'),'Microsoft.Network/publicIpAddresses', parameters('publicIpAddressName'))]"
            }
          }
        }
      ],
      "enableAcceleratedNetworking": true,
      "networkSecurityGroup": {
        "id": "[resourceId(parameters('nsgResourceGroupName'), 'Microsoft.Network/networkSecurityGroups', parameters('networkSecurityGroupName'))]"
      }
    }
  }   

在main.JSON中添加以下變量:

{
    "name": "[parameters('networkInterfaceName')]",
    "type": "Microsoft.Network/networkInterfaces",
    "apiVersion": "2018-04-01",
    "location": "[parameters('location')]",
    "dependsOn": [
      "[concat('Microsoft.Network/publicIpAddresses/', parameters('publicIpAddressName'))]"
    ],
    "properties": {
      "ipConfigurations": [
        {
          "name": "ipconfig1",
          "properties": {
            "subnet": {
              "id": "[variables('subnetRef')]"
            },
            "privateIPAllocationMethod": "Dynamic",
          }
        }
      ],
    }
  }

然后在main.JSON文件中添加以下參數:

"parameters": {
  "virtualNetworkName": {
  "type": "string"
},
"subnetName": {
  "type": "string"
},

在main.parameters.json中添加變量信息:

"virtualNetworkName": {
  "value": "<vnet name>"
},
"resourceGroupName": {
  "value": "<whatever the rg is for the Network>"
},
"subnetName": {
  "value": "<subnet name>"
},

希望能有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM