嵌套复制循环 ARM 模板
Nested copy loop ARM template
正在尝试使用双复制循环创建 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'))]"
}
}
}
]
}
目前一切顺利。它按预期部署了多个私有 DNS 区域。
现在我想更改模板,以便可以部署多个区域以及 link 将区域部署到多个 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 区域,但也通过虚拟网络。对我来说棘手的部分是我需要 link 名称中的两个循环的信息。
尝试了多种方法,但最终以模板中的语法错误或部署期间的错误告终。
希望有人能在正确的方向上推动我...
我成功了:
模板文件:
{
"$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"
}
]
}
}
}
正在尝试使用双复制循环创建 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'))]"
}
}
}
]
}
目前一切顺利。它按预期部署了多个私有 DNS 区域。 现在我想更改模板,以便可以部署多个区域以及 link 将区域部署到多个 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 区域,但也通过虚拟网络。对我来说棘手的部分是我需要 link 名称中的两个循环的信息。 尝试了多种方法,但最终以模板中的语法错误或部署期间的错误告终。
希望有人能在正确的方向上推动我...
我成功了: 模板文件:
{
"$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"
}
]
}
}
}