簡體   English   中英

通過ARM模板將子網添加到現有Vnet

[英]Addition of subnets to existing Vnet through ARM templates

以下是我的輸入參數文件(parameter.json)

    {
    "VNetSettings":{
    "value":{
        "name":"VNet2",
        "addressPrefixes":"10.0.0.0/16",
        "subnets":[
            {
                "name": "sub1",
                "addressPrefix": "10.0.1.0/24"
            },
            {
                "name":"sub2",
                "addressPrefix":"10.0.2.0/24"
            }
        ]
    }
  }
}

以下是我應該部署子網的手臂模板。(deploy.json)

   {
"contentversion":"1.0.0.0",
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"parameters":{
        "VNetSettings":{"type":"object"},
"noofsubnets":
        {
            "type":"int"
        },
"newOrExisting":
    {
        "type":"string",
        "allowedvalues":
            [
                "new",
                "existing"
            ]
    }
    },
"resources":
[{
  "condition":"[equals(parameters('newOrExisting'),'new')]",
  "type": "Microsoft.Network/virtualNetworks",
  "mode":"Incremental",
  "apiVersion": "2015-06-15",
  "name":"[parameters('VNetSettings').name]",
  "location":"[resourceGroup().location]",
  "properties":
  {
    "addressSpace":{
        "addressPrefixes":["[parameters('VNetSettings').addressPrefixes]"]
  },
    "copy":
       [{
         "name":"subnets",
         "count":"[parameters('noofsubnets')]",
         "input": 
             {
              "name": "[parameters('VNetSettings').subnets[copyIndex('subnets')].name]",
              "properties":
                 {
                   "addressPrefix": "[parameters('VNetSettings').subnets[copyIndex('subnets')].addressPrefix]"
                 }
             }
        }]

       }
  }]
}

模板應該做的是在現有子網的基礎上將這兩個子網(sub1和sub2)添加到Vnet中,但是它正在做的是用輸入文件中存在的這兩個子網替換現有子網。 模式:增量應該執行此操作,但是我不確定是否將其放置在正確的位置。 我正在使用以下Powershell命令部署此模板:

    New-AzureRmResourceGroupDeployment -Name testing -ResourceGroupName rgname -TemplateFile C:\Test\deploy.json -TemplateParameterFile C:\Test\parameterfile.json

這是預期的行為。 您應該閱讀“冪等”。 您需要做的是創建一個子網資源,這樣您就可以解決該問題。

{
    "apiVersion": "2016-03-30",
    "name": "vnetName\subnetName",
    "location": "[resourceGroup().location]]",
    "type": "Microsoft.Network/virtualNetworks/subnets",
    "properties": {
        "addressPrefix": "xx.x.x.xx"
    }
}

vnetName必須是您要在其中創建資源的vnet。

暫無
暫無

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

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