带数组的 ARM 模板复制
ARM Template Copy with Array
我正在尝试使用以下代码在 Azure 中部署大量私有 DNS 资源:
"variables": {
"blobDNSName": "privatelink.blob.core.windows.net",
"databaseDNSName": "privatelink.database.core.windows.net",
"datafactoryDNSName": "privatelink.datafactory.core.windows.net",
"dfsDNSName": "privatelink.dfs.core.windows.net",
"keyvaultDNSName": "privatelink.vaultcore.core.windows.net",
"blobTags": {
"value": {
"Application": "Monitor",
"CostCentre": "[parameters('costCentre')]",
"Criticality": "[parameters('criticality')]",
"Owner": "[parameters('owner')]",
"Project": "[parameters('project')]",
"Enviroment": "[parameters('environment')]"
}
},
"databaseTags": {
"value": {
"Application": "SQL",
"CostCentre": "[parameters('costCentre')]",
"Criticality": "[parameters('criticality')]",
"Owner": "[parameters('owner')]",
"Project": "[parameters('project')]",
"Enviroment": "[parameters('environment')]"
}
},
"datafactoryTags": {
"value": {
"Application": "Data Factory",
"CostCentre": "[parameters('costCentre')]",
"Criticality": "[parameters('criticality')]",
"Owner": "[parameters('owner')]",
"Project": "[parameters('project')]",
"Enviroment": "[parameters('environment')]"
}
},
"dfsTags": {
"value": {
"Application": "Data Lake",
"CostCentre": "[parameters('costCentre')]",
"Criticality": "[parameters('criticality')]",
"Owner": "[parameters('owner')]",
"Project": "[parameters('project')]",
"Enviroment": "[parameters('environment')]"
}
},
"keyvaultTags": {
"value": {
"Application": "Key Vault",
"CostCentre": "[parameters('costCentre')]",
"Criticality": "[parameters('criticality')]",
"Owner": "[parameters('owner')]",
"Project": "[parameters('project')]",
"Enviroment": "[parameters('environment')]"
}
},
"dnsArray": {
"value": [
{
"dns": "[variables('blobDNSName')]",
"tags": "[variables('blobTags')]"
},
{
"dns": "[variables('databaseDNSName')]",
"tags": "[variables('databaseTags')]"
},
{
"dns": "[variables('datafactoryDNSName')]",
"tags": "[variables('datafactoryTags')]"
},
{
"dns": "[variables('dfsDNSName')]",
"tags": "[variables('dfsTags')]"
},
{
"dns": "[variables('keyvaultDNSName')]",
"tags": "[variables('keyvaultTags')]"
}
]
}
和:
"resources": [
{
"type": "Microsoft.Network/privateDnsZones",
"apiVersion": "[utils.apiVersion('Microsoft.Network', 'privateDnsZones')]",
"name": "[variables('dnsArray')[copyIndex('dnsCopy')].dns]",
//"tags": "[[copyIndex('dnsCopy')].tags]",
"copy": {
"name": "dnsCopy",
"count": "[length(variables('dnsArray'))]"
},
"location": "global",
"properties": {
"maxNumberOfRecordSets": 25000,
"maxNumberOfVirtualNetworkLinks": 1000,
"maxNumberOfVirtualNetworkLinksWithRegistration": 100,
"numberOfRecordSets": 1,
"numberOfVirtualNetworkLinks": 0,
"numberOfVirtualNetworkLinksWithRegistration": 0,
"provisioningState": "Succeeded"
}
}]
我得到的错误是:
部署模板验证失败:'The template resource '[variables('dnsArray')[copyIndex('dnsCopy')].value.dns]' at line '150' and column '9' is not valid : 无法计算语言表达式 属性 '0',属性 名称必须是字符串。请参阅 https://aka.ms/arm-template-expressions 了解详细用法。'。 (代码:无效模板)
发生在这条线上:
"name": "[variables('dnsArray')[copyIndex('dnsCopy')].dns]",
我尝试的尝试可行吗?
经过多次摸索,我设法解决了这个问题,以防万一有人遇到这样的问题:
{
"type": "Microsoft.Network/privateDnsZones",
"apiVersion": "[utils.apiVersion('Microsoft.Network', 'privateDnsZones')]",
"name": "[variables('dnsArray').value[copyIndex('dnsCopy')].dns]",
"tags": "[variables('dnsArray').value[copyIndex('dnsCopy')].tags.value]",
"copy": {
"name": "dnsCopy",
"count": "[length(variables('dnsArray').value)]"
},
"location": "global",
"properties": {
"maxNumberOfRecordSets": 25000, "maxNumberOfVirtualNetworkLinks": 1000,
"maxNumberOfVirtualNetworkLinksWithRegistration": 100,
"numberOfRecordSets": 1,
"numberOfVirtualNetworkLinks": 0,
"numberOfVirtualNetworkLinksWithRegistration": 0,
"provisioningState": "Succeeded"
}
}
注意dnsArray后value的使用
我正在尝试使用以下代码在 Azure 中部署大量私有 DNS 资源:
"variables": {
"blobDNSName": "privatelink.blob.core.windows.net",
"databaseDNSName": "privatelink.database.core.windows.net",
"datafactoryDNSName": "privatelink.datafactory.core.windows.net",
"dfsDNSName": "privatelink.dfs.core.windows.net",
"keyvaultDNSName": "privatelink.vaultcore.core.windows.net",
"blobTags": {
"value": {
"Application": "Monitor",
"CostCentre": "[parameters('costCentre')]",
"Criticality": "[parameters('criticality')]",
"Owner": "[parameters('owner')]",
"Project": "[parameters('project')]",
"Enviroment": "[parameters('environment')]"
}
},
"databaseTags": {
"value": {
"Application": "SQL",
"CostCentre": "[parameters('costCentre')]",
"Criticality": "[parameters('criticality')]",
"Owner": "[parameters('owner')]",
"Project": "[parameters('project')]",
"Enviroment": "[parameters('environment')]"
}
},
"datafactoryTags": {
"value": {
"Application": "Data Factory",
"CostCentre": "[parameters('costCentre')]",
"Criticality": "[parameters('criticality')]",
"Owner": "[parameters('owner')]",
"Project": "[parameters('project')]",
"Enviroment": "[parameters('environment')]"
}
},
"dfsTags": {
"value": {
"Application": "Data Lake",
"CostCentre": "[parameters('costCentre')]",
"Criticality": "[parameters('criticality')]",
"Owner": "[parameters('owner')]",
"Project": "[parameters('project')]",
"Enviroment": "[parameters('environment')]"
}
},
"keyvaultTags": {
"value": {
"Application": "Key Vault",
"CostCentre": "[parameters('costCentre')]",
"Criticality": "[parameters('criticality')]",
"Owner": "[parameters('owner')]",
"Project": "[parameters('project')]",
"Enviroment": "[parameters('environment')]"
}
},
"dnsArray": {
"value": [
{
"dns": "[variables('blobDNSName')]",
"tags": "[variables('blobTags')]"
},
{
"dns": "[variables('databaseDNSName')]",
"tags": "[variables('databaseTags')]"
},
{
"dns": "[variables('datafactoryDNSName')]",
"tags": "[variables('datafactoryTags')]"
},
{
"dns": "[variables('dfsDNSName')]",
"tags": "[variables('dfsTags')]"
},
{
"dns": "[variables('keyvaultDNSName')]",
"tags": "[variables('keyvaultTags')]"
}
]
}
和:
"resources": [
{
"type": "Microsoft.Network/privateDnsZones",
"apiVersion": "[utils.apiVersion('Microsoft.Network', 'privateDnsZones')]",
"name": "[variables('dnsArray')[copyIndex('dnsCopy')].dns]",
//"tags": "[[copyIndex('dnsCopy')].tags]",
"copy": {
"name": "dnsCopy",
"count": "[length(variables('dnsArray'))]"
},
"location": "global",
"properties": {
"maxNumberOfRecordSets": 25000,
"maxNumberOfVirtualNetworkLinks": 1000,
"maxNumberOfVirtualNetworkLinksWithRegistration": 100,
"numberOfRecordSets": 1,
"numberOfVirtualNetworkLinks": 0,
"numberOfVirtualNetworkLinksWithRegistration": 0,
"provisioningState": "Succeeded"
}
}]
我得到的错误是: 部署模板验证失败:'The template resource '[variables('dnsArray')[copyIndex('dnsCopy')].value.dns]' at line '150' and column '9' is not valid : 无法计算语言表达式 属性 '0',属性 名称必须是字符串。请参阅 https://aka.ms/arm-template-expressions 了解详细用法。'。 (代码:无效模板)
发生在这条线上:
"name": "[variables('dnsArray')[copyIndex('dnsCopy')].dns]",
我尝试的尝试可行吗?
经过多次摸索,我设法解决了这个问题,以防万一有人遇到这样的问题:
{
"type": "Microsoft.Network/privateDnsZones",
"apiVersion": "[utils.apiVersion('Microsoft.Network', 'privateDnsZones')]",
"name": "[variables('dnsArray').value[copyIndex('dnsCopy')].dns]",
"tags": "[variables('dnsArray').value[copyIndex('dnsCopy')].tags.value]",
"copy": {
"name": "dnsCopy",
"count": "[length(variables('dnsArray').value)]"
},
"location": "global",
"properties": {
"maxNumberOfRecordSets": 25000, "maxNumberOfVirtualNetworkLinks": 1000,
"maxNumberOfVirtualNetworkLinksWithRegistration": 100,
"numberOfRecordSets": 1,
"numberOfVirtualNetworkLinks": 0,
"numberOfVirtualNetworkLinksWithRegistration": 0,
"provisioningState": "Succeeded"
}
}
注意dnsArray后value的使用