Azure ARM模板参数文件中的功能无法正常运行

问题描述

我正在研究一个Azure ARM模板,该模板可通过路由表部署vNet,并且对routerTable ID参考存在问题。该函数位于deploy.json内部时,所有方法均有效。但是,当我将所有参数定义移至param文件时,开始出现错误,抱怨属性ID无效

New-AzResourceGroupDeployment:-部署“ deploy-vnet”失败 有错误显示1个错误中的1个。状态消息:属性 路径上的id'[resourceId('Microsoft.Network/routeTables','后端')]' “ properties.subnets [0] .properties.routeTable.id”无效。期望 以开头的完全限定资源ID '/ subscriptions / {subscriptionId}'或 '/ providers / {resourceProviderNamespace} /'。 (代码: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#","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","nextHopIpAddress": "10.15.0.4"
                    }
                }
            ]
            }
        ]
    
        }  

    }
}

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

任何人都知道如何解决此问题???另一个观察结果是,该函数输出部分可以正常工作。

解决方法

我可以肯定地确定该函数在参数文件中不起作用,因此您的解决方法是-在powershell \ python \ etc等外部进行计算,然后将其编辑到参数文件中,或者仅在模板内部进行计算