gpt4 book ai didi

azure - 可以在 ARM 模板中执行嵌套复制循环吗?

转载 作者:行者123 更新时间:2023-12-05 03:48:47 26 4
gpt4 key购买 nike

我正在尝试动态生成路径映射,以将传入流量路由到应用程序网关的正确后端池。

例如,我们有 20 个租户,每个后端池允许 5 个租户,这意味着我们将生成 4 个后端池。

我需要动态创建路径映射,以便后端池一为租户 1-5 提供服务,后端池二为租户 6-10 提供服务,等等。

我想要生成的所需数组是:

[
[ "tenant1", "tenant2", "tenant3", "tenant4", "tenant5"],
["tenant6", "tenant7", "tenant8", "tenant9", "tenant10"],
["tenant11", "tenant12", "tenant13", "tenant14", "tenant15"],
["tenant16", "tenant17", "tenant18", "tenant19", "tenant20"]
]

形成此数组后,我可以创建后端池并连接子数组字符串以形成我需要的路径映射。

这是其中一项尝试的快速原型(prototype)......

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
},
"variables": {
"totalTenants": 20,
"tenantsPerBackendPool": 5,
"copy": [
{
"name": "outerCopy",
"count": "[div(variables('totalTenants'), variables('tenantsPerBackendPool'))]",
"input": {
"copy": {
"count": "[variables('totalTenants')]",
"name": "innerCopy",
"input": "[if(equals(div(copyIndex('innerCopy'), 5), copyIndex('outerCopy')), concat('/tenant', copyIndex('innerCopy'), '/*'), json('null'))]"
}
}
}
]
},
"resources": [
// Multiple backend pools will be created here, and use the path mappings to route correctly
],
"outputs": {
"pathMappings": {
"type": "array",
"value": "[variables('outerCopy')]"
}
}
}

但是我遇到以下异常: New-AzResourceGroupDeployment: 16:01:18 - Error: Code=InvalidTemplate; Message=Deployment template language expression evaluation failed: 'The template language function 'copyIndex' has an invalid argument. The provided copy name 'innerCopy' doesn't exist in the resource.

最佳答案

我很确定你不能在OP中执行嵌套方法,但我认为你可以生成你想要的数组的数组:

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {
"totalTenants": 20,
"tenantsPerBackendPool": 5,
"copy": [
{
"name": "firstPass",
"count": "[variables('totalTenants')]",
"input": "[concat('/tenant', copyIndex('firstPass', 1), '/*')]"
},
{
"name": "finalpass",
"count": "[div(variables('totalTenants'), variables('tenantsPerBackendPool'))]",
"input": "[take(skip(variables('firstPass'), mul(variables('tenantsPerBackendPool'), copyIndex('finalPass'))), variables('tenantsPerBackendPool'))]"
}
]
},
"resources": [ ],
"outputs": {
"firstPass": {
"type": "array",
"value": "[variables('firstPass')]"
},
"finalPass": {
"type": "array",
"value": "[variables('finalpass')]"
}
}
}

有帮助吗?

关于azure - 可以在 ARM 模板中执行嵌套复制循环吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64229005/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com