ARM模板复制功能未从参数中选取值

问题描述 投票:-1回答:1

您好,我已经创建了一个简单的ARM模板来创建Route表和路由,我试图在属性中使用Copy函数来基于参数数组定义路由。以下是编写的代码

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "routetablename": {
      "type": "string",
      "defaultValue": "DDS-SHD-ROUTETABLE",
      "metadata": {
        "displayName": "Route Table Name"
      }
    },
    "disableBgpRoutePropagation": {
        "type": "string",
        "defaultValue": "false",
        "metadata": {
          "description": "Route Propagation."
        }
    },


    "DD": {
        "type": "array",
        "defaultValue":  [
          "10.0.0.0/24",
          "10.1.0.0/24",
          "10.2.0.0/24"],
        "metadata": {
          "description": "OnPremises Address Prefix for Subnet01."
        }
    },


        "tagvalue": {
      "type": "string",
      "defaultValue": "Shared Network Services",
      "metadata": {
        "description": "Tag Value for Resource."
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for all resources."
      }
    }
  },
  "variables": {
    "routetablename": "[parameters('routetablename')]",
    "tagvalue": "[parameters('tagvalue')]",
    "location": "[parameters('location')]"


  },
  "resources": [
    {
        "name": "[variables('routetablename')]",
        "type": "Microsoft.Network/routeTables",
        "apiVersion": "2019-02-01",
        "location": "[variables('location')]",
        "tags": {
        "app": "[variables('tagvalue')]"
        },
        "dependsOn": [],
        "properties": {
            "disableBgpRoutePropagation": "[parameters('disableBgpRoutePropagation')]",
        "Copy":
              [
            { 
              "name": "routes",
              "count": "[length(parameters('DD'))]",
              "input": {
                "name": "[concat('OnPrem',copyIndex('routes'))]",
                 "addressPrefix": "[parameters('DD')]",
                "nextHopType": "VirtualNetworkGateway"
              }
            }
          ]

      }
    }
  ]
}

根据我的理解,我应该获得1条路线表以及3条路线,即Onprem0OnPrem1OnPrem2

相反,我得到以下错误“细节”: [{“ code”:“ AddressPrefixStringCannotBeNullOrEmpty”,“ message”:“资源/subscriptions/................./.resourceGroups/CAZAUSE-的地址前缀字符串MGMT-NETWORK-RG / providers / Microsoft.Network / routeTables / DDS-SHD-ROUTETABLE / routes / OnPrem0不能为null或为空。“,“详细信息”:[]

任何帮助将不胜感激。

json azure copy azure-resource-manager
1个回答
0
投票

此固定值在AddressSuffix参数中缺少COpyIndex()如下

"Copy":
              [
            { 
              "name": "routes",
              "count": "[length(parameters('DD'))]",
              "input": {
                "name": "[concat('OnPrem-',copyIndex('routes'))]",
                "properties": {
                 "addressPrefix": "[parameters('DD')[copyIndex('routes')]]",
                "nextHopType": "VirtualNetworkGateway"
© www.soinside.com 2019 - 2024. All rights reserved.