gpt4 book ai didi

azure - 嵌套复制循环ARM模板

转载 作者:行者123 更新时间:2023-12-03 07:03:14 28 4
gpt4 key购买 nike

尝试创建具有双复制循环的 ARM 模板:

    {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"privateDnsZones": {
"type": "array",
"metadata": {
"description": "List of private DNS zones to create"
},
"allowedValues": [
"privatelink.azure-automation.net", // Azure Automation / Webhook,
"and more"
]
},
"virtualNetworkName": {
"type": "string",
"metadata": {
"description": "Name of the Virtual Network to attach the PrivateLink DNS Zones to."
}
},
"virtualNetworkResourceGroupName": {
"type": "string",
"metadata": {
"description": "Name of the Resource Group containing the Virtual Network."
}
}
},
"resources": [
{
"type": "Microsoft.Network/privateDnsZones",
"name": "[parameters('privateDnsZones')[copyIndex()]]",
"apiVersion": "2020-01-01",
"location": "global",
"copy": {
"name": "zone",
"count": "[length(parameters('privateDnsZones'))]"
}
},
{
"type": "Microsoft.Network/privateDnsZones/virtualNetworkLinks",
"name": "[concat(parameters('privateDnsZones')[copyIndex('link')], '/', parameters('virtualNetworkResourceGroupName'),'-',parameters('virtualNetworkName'))]",
"apiVersion": "2020-06-01",
"location": "global",
"copy": {
"name": "link",
"count": "[length(parameters('privateDnsZones'))]"
},
"dependsOn": [
"zone"
],
"properties": {
"registrationEnabled": false,
"virtualNetwork": {
"id": "[resourceId(parameters('virtualNetworkResourceGroupName'), 'Microsoft.Network/virtualNetworks', parameters('virtualNetworkName'))]"
}
}
}
]
}

到目前为止一切进展顺利。它按预期部署多个私有(private) DNS 区域。现在我想更改模板,以便可以部署多个区域并将这些区域链接到多个 vNet。

参数文件看起来像这样:

    {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"privateDnsZones": {
"value": [
"privatelink.blob.core.windows.net",
"privatelink.table.core.windows.net"
]
},
"virtualNetwork": {
"value": [
{
"vnetName": "vnet1",
"resourceGroup": "vnet1",
"subscriptionId": "11111111-1111-1111-1111-111111111111"
},
{
"vnetName": "vnet2",
"resourceGroup": "vnet2",
"subscriptionId": "22222222-2222-2222-2222-222222222222"
}
]
}
}
}

想法是模板通过Pricate DNS 区域循环,但也通过虚拟网络循环。对我来说,棘手的部分是我需要链接名称中两个循环的信息。尝试了多种方法,但最终出现模板内的语法错误或部署期间的错误。

希望有人能插入我朝正确的方向前进......

最佳答案

我让它工作了:模板文件:

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"privateDnsZones": {
"type": "array",
"metadata": {
"description": "List of private DNS zones to create"
},
"allowedValues": [
"privatelink.azure-automation.net", // Azure Automation / Webhook, DSCAndHybridWorker
"privatelink.database.windows.net", // Azure SQL Database / SQL Server / Azure Synapse Analytics
"and many more...."
]
},
"virtualNetworks": {
"type": "array",
"metadata": {
"description": "Name of the Virtual Network to attach the PrivateLink DNS Zones to."
}
}
},
"variables": {
"NumberOfLoops": "[mul(length(parameters('privateDnsZones')),length(parameters('virtualNetworks')))]",
"lengthPrivateDnsZones": "[length(parameters('privateDnsZones'))]",
"lengthvirtualNetworks": "[length(parameters('virtualNetworks'))]"
},
"resources": [
{
"type": "Microsoft.Network/privateDnsZones",
"name": "[parameters('privateDnsZones')[copyIndex()]]",
"apiVersion": "2020-01-01",
"location": "global",
"copy": {
"name": "zone",
"count": "[length(parameters('privateDnsZones'))]"
}
},
{
"type": "Microsoft.Network/privateDnsZones/virtualNetworkLinks",
"name": "[concat(parameters('privateDnsZones')[mod(copyIndex(),variables('lengthPrivateDnsZones'))], '/', parameters('virtualNetworks')[mod(div(copyIndex(),variables('lengthPrivateDnsZones')),variables('lengthvirtualNetworks'))].resourceGroup,'-',parameters('virtualNetworks')[mod(div(copyIndex(),variables('lengthPrivateDnsZones')),variables('lengthvirtualNetworks'))].vnetName)]",
"apiVersion": "2020-06-01",
"location": "global",
"copy": {
"name": "link",
"count": "[variables('NumberOfLoops')]"
},
"dependsOn": [
"zone"
],
"properties": {
"registrationEnabled": false,
"virtualNetwork": {
"id": "[resourceId(parameters('virtualNetworks')[mod(div(copyIndex(),variables('lengthPrivateDnsZones')),variables('lengthvirtualNetworks'))].subscriptionId, parameters('virtualNetworks')[mod(div(copyIndex(),variables('lengthPrivateDnsZones')),variables('lengthvirtualNetworks'))].resourceGroup, 'Microsoft.Network/virtualNetworks', parameters('virtualNetworks')[mod(div(copyIndex(),variables('lengthPrivateDnsZones')),variables('lengthvirtualNetworks'))].vnetName)]"
}
}
}
]

}

参数文件:

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"privateDnsZones": {
"value": [
"privatelink.azure-automation.net",
"privatelink.database.windows.net",
"privatelink.blob.core.windows.net",
"privatelink.table.core.windows.net",
"privatelink.vaultcore.azure.net",
"privatelink.mariadb.database.azure.com",
"privatelink.service.signalr.net"
]
},
"virtualNetworks": {
"value": [
{
"vnetName": "vnet1",
"resourceGroup": "vnet1",
"subscriptionId": "GUID"
},
{
"vnetName": "vnet2",
"resourceGroup": "vnet2",
"subscriptionId": "GUID"
}
]
}
}

}

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

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