azure - 从参数文件传入子网委派
问题描述
我正在尝试使用从参数文件更新子网委托,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"
}
}
]
},
只是无法弄清楚我哪里出错了。
解决方案
根据您收到的错误,我认为问题与您正在构建的循环有关。将循环更改为以下内容:
subnets: [for (subnet, j) in VNetSettings.subnets):
现在,subnet
将包含您当前的子网对象,j
并将反映您当前所在的循环索引。这更正了您看到的错误 - 值得注意的是,它表示您的数组索引无效,因为您试图传入原始问题中实际上不是索引的东西。
然后只需对子网对象本身进行一些调整,以反映您在循环中使用的引用的使用(而不是数组索引)。
{
name: subnet.delegations.name
properties: {
serviceName: subnet.delegations.properties.serviceName
}
推荐阅读
- typescript - Firebase rxfire 订阅检查我的代码
- python - 如何在不使用循环的情况下获取 python beautifulsoup 中的特定部分
- python - 熊猫数据框中条件过滤的通用函数
- javascript - 为什么我们不能在全局情况下用 let 重新声明变量
- sql-server - Kafka Connect CDC 到 MS SQL sourceOffset 异常
- node.js - TypeError:无法使用烤盘 1.0.3 读取未定义的属性“字符串”并做出反应 16.2.0
- r - 当按列传递损失时,H2O.GeneralizedLowRankModel 目标为 NA
- git - 是否有存储存储库元数据的标准格式?
- ruby - 遍历列表Ruby时如何跳过元素
- javascript - 如何从目录中删除两个最低的文件(按其名称)