首页 > 解决方案 > 从参数文件传入子网委派

问题描述

我正在尝试使用从参数文件更新子网委托,BICEP但不断收到错误,我无法找出原因。

The language expression property 'name' has an invalid array index.

二头肌文件:

subnets: [for j in range(0, length(VNetSettings.subnets)): {

          {
            name: VNetSettings.subnets[j].delegations.name
            properties: {
              serviceName: VNetSettings.subnets[j].delegations.properties.serviceName
            }
          }
        ]

参数文件:

            "value": {
                "Name": "vnet",
                "addressPrefix": "10.230.0.0/23",
                "subnets": [
                    {
                        "name": "data",
                        "addressPrefix": "10.230.1.64/26",
                        "routeTable": "",
                        "unique": false,
                        "nsgRules": [
                            {
                                "name": "DENY-ALL-VNET-INBOUND",
                                "description": "Deny all Virtual Network traffic",
                                "priority": "4000",
                                "direction": "Inbound",
                                "access": "Deny",
                                "protocol": "*",
                                "sourcePortRange": "*",
                                "destinationPortRange": "*",
                                "sourceAddressPrefix": "VirtualNetwork",
                                "destinationAddressPrefix": "VirtualNetwork"
                            }
                        ],
                        "serviceEndpoints":[],
                        "delegations": [
                            {
                                "name": "Microsoft.Web.serverFarms",
                                "properties": {
                                    "serviceName": "Microsoft.Web/serverFarms"
                                }
                            } 
                        ]
                    },

只是无法弄清楚我哪里出错了。

标签: azureazure-bicep

解决方案


根据您收到的错误,我认为问题与您正在构建的循环有关。将循环更改为以下内容:

subnets: [for (subnet, j) in VNetSettings.subnets):

现在,subnet将包含您当前的子网对象,j并将反映您当前所在的循环索引。这更正了您看到的错误 - 值得注意的是,它表示您的数组索引无效,因为您试图传入原始问题中实际上不是索引的东西。

然后只需对子网对象本身进行一些调整,以反映您在循环中使用的引用的使用(而不是数组索引)。

{
  name: subnet.delegations.name  
  properties: {
    serviceName: subnet.delegations.properties.serviceName
}

推荐阅读