Azure 资源管理器模板 - 属性 循环不工作不断收到错误,因为不需要复制索引

Azure resource manager template - property loops is not working keep getting error as copyindex is not expected

我正在尝试根据负载均衡器的可用文档 https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/copy-properties 使用属性复制循环部署 Arm 模板,但它无法正常工作。模板验证失败错误为“无法评估语言表达式 属性 'protocol'。

如果我删除负载均衡器规则副本并尝试单独迭代健康探测器 属性 它的工作。

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymenttemplate.json#",
"contentversion": "1.0.0.0",
"parameters": {

.......

    "lbprobe": {
        "type": "array",
        "defaultValue": [
            {
                "name": "customAppPort",
                "frontendPort": "8080",
                "backendPort": "8888",
                "protocolprobe": "tcp",
                "protocol": "tcp"
            },
            {
                "name": "httpsPort",
                "frontendPort": "443",
                "backendPort": "443",
                "protocolprobe": "tcp",
                "protocol": "tcp"
            }

        ],
        "metadata": {
            "description": "description"
        }
    }
},
"functions": [],
"variables": {},
 "resources": [
    {
        "name": "[parameters('lbname')]",
        "type": "Microsoft.Network/loadBalancers",
        "apiVersion": "2020-11-01",
        "location": "[resourceGroup().location]",
        "sku": {
            "name": "Standard",
            "tier": "Regional"
        },
        "properties": {
            "frontendIPConfigurations": [
                {
                    "name": "[parameters('lbfrontendip')]",
                    "properties": {
                        "privateIPAllocationMethod": "Dynamic",
                        "subnet": {
                            "id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', 'testvnet-01', 'default')]"
                        }
                    }
                }
            ],
            "backendAddressPools": [
                {
                    "name": "[parameters('lbbackendpool')]"
                }
            ],
            "copy": [
                
                {
                    "name": "loadBalancingRules",
                    "count": "[length(parameters('lbprobe'))]",
                    "input": {
                        "name": "[parameters('lbprobe')[copyIndex('loadBalancingRules')].name]",
                        "properties": {
                            "frontendipconfiguration": {
                                "id": "[resourceid('microsoft.network/loadbalancers/frontendipconfigurations', parameters('lbname'), parameters('lbfrontendip'))]"
                            },
                            "backendaddresspool": {
                                "id": "[resourceid('microsoft.network/loadbalancers/backendaddresspools', parameters('lbname'), parameters('lbbackendpool'))]"
                            },
                            "protocol": "[parameters('lbprobe')[copyIndex('loadBalancingRules').protocol]]",
                            "frontendport": "[parameters('lbprobe')[copyIndex('loadBalancingRules').frontendPort]]",
                            "backendport": "[parameters('lbprobe')[copyIndex('loadBalancingRules').backendPort]]",
                            "enablefloatingip": false,
                            "idletimeoutinminutes": 5,
                            "probe": {
                                "id": "[resourceid('microsoft.network/loadbalancers/probes', parameters('lbname'),parameters('lbprobe')[copyIndex('loadBalancingRules')].name)]"
                            }

                        }
                    }
                },
                {
                    "name": "Probes",
                    "count": "[length(parameters('lbprobe'))]",
                    "input": {
                        "name": "[parameters('lbprobe')[copyIndex('Probes')].name]",
                        "properties": {
                            "protocol": "[parameters('lbprobe')[copyIndex('Probes')].protocolprobe]",
                            "port": "[parameters('lbprobe')[copyIndex('Probes')].frontendPort]",
                            "intervalInSeconds": 5,
                            "numberOfProbes": 2
                        }
                    }
                }

            ]

        }
    }
],
"outputs": {}

}

我们已经尝试了相同的代码,能够重现上述问题并找出根本原因。

错误详情:-

在您复制的模板中 loadBalancingRules 您正在使用以下内容:

"protocol": "[parameters('lbprobe')[copyIndex('loadBalancingRules').protocol]]",
                            "frontendport": "[parameters('lbprobe')[copyIndex('loadBalancingRules').frontendPort]]",
                            "backendport": "[parameters('lbprobe')[copyIndex('loadBalancingRules').backendPort]]",

您应该使用以下内容:

"protocol": "[parameters('lbprobe')[copyIndex('loadBalancingRules')].protocol]",
"frontendport": "[parameters('lbprobe')[copyIndex('loadBalancingRules')].frontendPort]",
"backendport": "[parameters('lbprobe')[copyIndex('loadBalancingRules')].backendPort]",

输出详细信息:-