微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Azure FrontDoor:如何设置内部具有多个实例的backendPool?

如何解决Azure FrontDoor:如何设置内部具有多个实例的backendPool?

我使用ARM模板将基础结构作为代码启动,以前我的所有部署都是使用Powershell进行的。希望您能帮助我解决此问题。

我想部署{2应用程序服务+ Azure FrontDoor]。在FrontDoor-Backendpool中,我想定义2个appservices。在我的代码下面:

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#","contentVersion": "1.0.0.0","parameters": {
    "location": {
        "type": "array","Metadata": {
            "description": "array of region"
        },"defaultValue": [
            "centralus","eastus"
        ]
    },"Stage": {
        "type": "string","Metadata": {
            "description": "Stage dev,prod"
        },"allowedValues": [
            "Dev","Prod"
        ],"defaultValue": "Dev"
    }
},"functions": [],"variables": {
    "appServicePlanName": "[concat('AppServicePlan-',parameters('Stage'),'-')]","appServiceName": "[concat('AppService-',"frontDoorName": "[concat('FrontDoor-',uniqueString(resourceGroup().id))]"
},"resources": [
    { // App Service Plan
        "type": "Microsoft.Web/serverfarms","name": "[concat(variables('appServicePlanName'),parameters('location')[copyIndex()])]","apiVersion": "2018-02-01","copy": {
            "count": "[length(parameters('location'))]","name": "copy multiple"
        },"location": "[parameters('location')[copyIndex()]]","sku": {
            "name": "F1","capacity": 1
        },"tags": {
            "cost": "[parameters('Stage')]"
        },"properties": {
            "name": "[concat(variables('appServicePlanName'),parameters('location')[copyIndex()])]"
        }
    },{ // App Services
        "type": "Microsoft.Web/sites","name": "[concat(variables('appServiceName'),"apiVersion": "2018-11-01","copy": {
            "name": "copy website","count": "[length(parameters('location'))]"
        },"dependsOn": [
            "[resourceId('Microsoft.Web/serverfarms',concat(variables('appServicePlanName'),parameters('location')[copyIndex()]))]"
        ],"properties": {
            "name": "[concat(variables('appServiceName'),"serverFarmId": "[resourceId('Microsoft.Web/serverfarms',parameters('location')[copyIndex()]))]"
        }
    },{ // Front Door
        "type": "Microsoft.Network/frontDoors","apiVersion": "2020-05-01","name": "[variables('frontDoorName')]","location": "global","properties": {
            "routingRules": [
                {
                    "name": "routingRule1","properties": {
                        "frontendEndpoints": [
                            {
                                "id": "[resourceId('Microsoft.Network/frontDoors/frontendEndpoints',variables('frontDoorName'),'frontendEndpoint1')]"
                            }
                        ],"acceptedProtocols": [
                            "Http","Https"
                        ],"patternsToMatch": [
                            "/*"
                        ],"routeConfiguration": {
                            "@odata.type": "#Microsoft.Azure.FrontDoor.Models.FrontdoorForwardingConfiguration","forwardingProtocol": "MatchRequest","backendPool": {
                                "id": "[resourceId('Microsoft.Network/frontDoors/backendPools','backendPool1')]"
                            }
                        },"enabledState": "Enabled"
                    }
                }
            ],"healthProbeSettings": [
                {
                    "name": "healthProbeSettings1","properties": {
                        "path": "/","protocol": "Http","intervalInSeconds": 120
                    }
                }
            ],"loadBalancingSettings": [
                {
                    "name": "loadBalancingSettings1","properties": {
                        "sampleSize": 4,"successfulSamplesrequired": 2
                    }
                }
            ],"backendPools": [
                {
                    "id": "backendPool1","name": "backendPool1","properties": {
                        "copy": [
                            {
                                "name": "backends","count": "[length(parameters('location'))]","input": {
                                    "address": "[concat(variables('appServiceName'),parameters('location')[copyIndex()],'.azurewebsites.net') ]","httpPort": 80,"httpsPort": 443,"weight": 50,"priority": 1,"enabledState": "Enabled"
                                }
                            }
                        ],"loadBalancingSettings": {
                            "id": "[resourceId('Microsoft.Network/frontDoors/loadBalancingSettings','loadBalancingSettings1')]"
                        },"healthProbeSettings": {
                            "id": "[resourceId('Microsoft.Network/frontDoors/healthProbeSettings','healthProbeSettings1')]"
                        }
                    }
                }
            ],"frontendEndpoints": [
                {
                    "name": "frontendEndpoint1","properties": {
                        "hostName": "[concat(variables('frontDoorName'),'.azurefd.net')]","sessionAffinityEnabledState": "Enabled"
                    }
                }
            ],"enabledState": "Enabled"
        }
    }

],"outputs": {}

}

您可以看到,我在参数位置上进行了迭代,以创建我的AppService计划和AppService,并且效果很好。所以我想对BackEndpool也做同样的事情。

这部分代码伤了我的脑筋

address": "[concat(variables('appServiceName'),

内部有些错误,但我不知道为什么。 重新调整的错误是: 错误:Code = InvalidTemplate; Message =部署模板语言表达评估 失败:'模板语言函数'copyIndex'具有无效的参数。提供的副本名称“”在资源中不存在。 有关用法的详细信息,请参见https://aka.ms/arm-copy。”。有关用法的详细信息,请参见https://aka.ms/arm-template-expressions

我从MS官方文档link from MS中汲取了灵感 关于如何解决它的任何想法吗? 谢谢

解决方法

您需要在copy部分对copyIndex的调用中包含backendPools name属性。这就是为什么说“提供的副本名称不存在”的原因。属性副本与资源副本的处理方式略有不同。

“ loopName属性使您可以指定copyIndex是指资源迭代还是属性迭代。如果没有为loopName提供值,则使用当前资源类型迭代。在对属性进行迭代时,为loopName提供一个值。 ” 来源:https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/template-functions-numeric#copyindex

parameters('location')[copyIndex('backends')]

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。