我尝试使用copyIndex()创建具有不同名称的子网,但出现错误
"message": "Resource
/subscriptions//resourceGroups//providers/Microsoft.Network/virtualNetworks/ has two child
resources with the same name
([parameters('subnets').subnetProperties[copyIndex('subnets')].name)).
但是我遵循文档操作来使用copy,这就是我一直在使用的,所以我不确定为什么不将其移至next name属性:
"resources": [
{
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2016-03-30",
"name": "[parameters('virtualNetworkName')]",
"location": "[parameters('location')]",
"tags": "[parameters('virtualNetworkTags')]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"[parameters('vNetAddressSpaces')]"
]
},
"copy": [
{
"name": "subnets",
"count": "[parameters('numberOfSubnets')]",
"input": {
"name": "[parameters('subnets').subnetProperties[copyIndex('subnets')].name)",
"properties": {
"addressPrefix": "[parameters('subnets').subnetProperties[copyIndex('subnets')].addressPrefix]"
}
}
}
]
}
},
Param文件:
"subnets":{
"value":{
"subnetProperties":[
{
"name":"firstSubnet",
"addressPrefix":"10.0.0.0/24"
},
{
"name":"secondSubnet",
"addressPrefix":"10.0.1.0/24"
}
]
}
},
我也尝试过使用copyIndex(),但是会抛出
template language expression evaluation failed: 'The template language
function 'copyIndex' has an invalid argument. The provided copy name '' doesn't exist in the
resource.
答案 0 :(得分:1)
我认为您搞砸了这一行中的括号:
"name": "[parameters('subnets').subnetProperties[copyIndex('subnets')].name)",
它应该像这样:
"name": "[parameters('subnets').subnetProperties[copyIndex('subnets')].name]",
最后一个括号是错误的。如果方括号不匹配,则不会处理完整的表达式。这将在第二个循环中产生相同的名称。
问候, 柯克