Azure ARM 模板参数文件中的函数无法正常工作

Functions inside Azure ARM Template param files are not been working

我正在开发一个 Azure ARM 模板,用于部署带有路由表的 vNet,但 routerTable ID 引用有问题。当函数在 deploy.json 内时一切正常。但是,当我将所有参数定义移动到参数文件时,我开始收到错误抱怨 属性 id is invalid

New-AzResourceGroupDeployment: - The deployment 'deploy-vnet' failed with error(s). Showing 1 out of 1 error(s). Status Message: Property id '[resourceId('Microsoft.Network/routeTables', 'Backend')]' at path 'properties.subnets[0].properties.routeTable.id' is invalid. Expect fully qualified resource Id that start with '/subscriptions/{subscriptionId}' or '/providers/{resourceProviderNamespace}/'. (Code:LinkedInvalidPropertyId)

这是 ARM 模板:

 // Deploy ARM Template
{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "VNetSettings": { "type": "object" },
        "RouteTables": { "type": "array" }
    },
    "functions": [],
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Network/routeTables",
            "apiVersion": "2020-05-01",
            "name": "[parameters('RouteTables')[copyIndex('routetablecopy')].name]",
            "location": "eastus2",
            "properties": {
                "disableBgpRoutePropagation": false,
                "routes": "[parameters('RouteTables')[copyIndex('routetablecopy')].routes]"
            },
            "copy": {
                "name": "routetablecopy",
                "count": "[length(parameters('RouteTables'))]"
            }
        },
        {
            "apiVersion": "2020-06-01",
            "type": "Microsoft.Network/virtualNetworks",
            "name": "[parameters('VNetSettings').name]",
            "location": "[resourceGroup().location]",
            "properties": {
                "addressSpace": {
                    "addressPrefixes": [
                        "[parameters('VNetSettings').addressPrefixes[0].addressPrefix]"
                    ]
                },
                "subnets":"[parameters('VNetSettings').subnets]"

            }
        }
    ],
    "outputs": {
        "text": {
            "type": "string",
            "value": "Hello Testing"
        },
        "routetableoutput": {
            "type": "string",
            "value": "[resourceId('Microsoft.Network/routeTables', 'Backend')]"
        }
    }
}

这是我使用的参数文件:

///PARAM FILE
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "VNetSettings": {
            "value": {
                "name": "fd-ARM-vnet",
                "addressPrefixes": [{
                    "name": "firstPrefix",
                    "addressPrefix": "10.15.0.0/16"
                }],
                "subnets": [{
                        "name": "Frontend",
                        "properties": {
                            "addressPrefix": "10.15.0.0/24",
                            "routeTable": {
                                **"id": "[resourceId('Microsoft.Network/routeTables', 'Backend')]"**
                            }
                        }
                    },
                    {
                        "name": "Backend",
                        "properties": {
                            "addressPrefix": "10.15.1.0/24"
                        }
                    }
                ]
            }
        },
        "RouteTables": {
            "value": [
            {
                "name": "Backend",
                "routes": [{
                    "name": "To-Internet",
                    "properties": {
                        "addressPrefix": "0.0.0.0/0",
                        "nextHopType": "VirtualAppliance",
                        "nextHopIpAddress": "10.15.1.4"
                    }
                }]
            },
            {
                "name": "Frontend",
                "routes": [{
                    "name": "Local-Subnet",
                    "properties": {
                        "addressPrefix": "10.15.0.0/24",
                        "nextHopType": "VnetLocal"
                    }
                },
                {
                    "name": "To-Internal",
                    "properties": {
                        "addressPrefix": "10.15.0.0/16",
                        "nextHopType": "VirtualAppliance",
                        "nextHopIpAddress": "10.15.0.4"
                    }
                }
            ]
            }
        ]
    
        }  

    }
}

如果我在文件中创建没有“routeTable”属性 的 VNET,它工作正常,但 routeTable 没有附加到子网。如果我使用: “[resourceId('Microsoft.Network/routeTables', 'Backend')]” 要么 “[参考(资源 ID('Microsoft.Network/routeTables','Backend'))]” 我收到相同的无效 属性 错误消息。

有人知道如何解决这个问题吗???另一个观察是相同的函数在输出部分工作正常。

我相当确定函数在参数文件中不起作用,所以您的解决方法是 - 在外部(在 powershell\python\etc 中)计算它们并将它们编辑到参数文件中,或者只是在模板中计算它们