繁体   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