【问题标题】:Functions inside Azure ARM Template param files are not been workingAzure ARM 模板参数文件中的函数无法正常工作
【发布时间】:2020-08-27 17:23:05
【问题描述】:

我正在使用 Azure ARM 模板来部署带有路由表的 vNet,但路由器表 ID 参考存在问题。当函数在 deploy.json 中时,这一切都有效。但是,当我将所有参数定义移动到参数文件时,我开始收到错误消息,抱怨属性 id 无效

New-AzResourceGroupDeployment:- 部署“deploy-vnet”失败 有错误。显示 1 个错误中的 1 个。状态消息:属性 id '[resourceId('Microsoft.Network/routeTables', 'Backend')]' 在路径 'properties.subnets[0].properties.routeTable.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#",
    "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')]” 或者 “[reference(resourceId('Microsoft.Network/routeTables', 'Backend'))]” 我收到相同的无效属性错误消息。

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

【问题讨论】:

    标签: azure templates azure-resource-manager


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多