嵌套资源的嵌套资源
Nested resources for nested resources
我正在构建一个创建多个存储帐户的 ARM 模板,每个帐户都将包含多个容器“blob”,但显然仍不受支持。
除了分别指定它们之外,还有其他方法可以做到这一点吗?
我想要实现的示例:
StorageAcct_1:必须包含 10 个 blob
StorageAcct_2 : 必须包含 6 个 blob
如果不复制我的存储帐户和容器模板,我将无法实现。
你可以做到 - 有多种方式(嵌套、内联、变量循环),这实际上取决于你希望代码看起来像什么以及你的输入格式是什么......但是一个简单的 n*m循环可以使用这个:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"variables": {
"numberOfAccounts": 2,
"blobsPerAccount": 3,
"saprefix": "[uniqueString(resourceGroup().id)]"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2021-08-01",
"name": "[format('{0}{1}', variables('saprefix'), copyIndex())]",
"location": "[resourceGroup().location]",
"sku": {
"name": "Standard_LRS"
},
"kind": "StorageV2",
"copy": {
"name": "storageAccountLoop",
"count": "[variables('numberOfAccounts')]"
}
},
{
"type": "Microsoft.Storage/storageAccounts/blobServices",
"apiVersion": "2021-08-01",
"name": "[format('{0}{1}/default', variables('saprefix'), copyIndex())]",
"copy": {
"name": "blobServiceLoop",
"count": "[variables('numberOfAccounts')]"
},
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts', format('{0}{1}', variables('saprefix'), copyIndex()))]"
]
},
{
"type": "Microsoft.Storage/storageAccounts/blobServices/containers",
"apiVersion": "2021-08-01",
"name": "[format('{0}{1}/{2}/{3}{4}', variables('saprefix'), mod(copyIndex(), variables('numberOfAccounts')), 'default', 'container', mod(copyIndex(), variables('blobsPerAccount')))]",
"copy": {
"name": "containerLoop",
"count": "[mul(variables('numberOfAccounts'), variables('blobsPerAccount'))]"
},
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts', format('{0}{1}', variables('saprefix'), mod(copyIndex(), variables('numberOfAccounts'))))]",
"[resourceId('Microsoft.Storage/storageAccounts/blobServices', format('{0}{1}', variables('saprefix'), mod(copyIndex(), variables('numberOfAccounts'))), 'default')]"
]
}
]
}
有帮助吗?
我正在构建一个创建多个存储帐户的 ARM 模板,每个帐户都将包含多个容器“blob”,但显然仍不受支持。 除了分别指定它们之外,还有其他方法可以做到这一点吗?
我想要实现的示例:
StorageAcct_1:必须包含 10 个 blob StorageAcct_2 : 必须包含 6 个 blob
如果不复制我的存储帐户和容器模板,我将无法实现。
你可以做到 - 有多种方式(嵌套、内联、变量循环),这实际上取决于你希望代码看起来像什么以及你的输入格式是什么......但是一个简单的 n*m循环可以使用这个:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"variables": {
"numberOfAccounts": 2,
"blobsPerAccount": 3,
"saprefix": "[uniqueString(resourceGroup().id)]"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2021-08-01",
"name": "[format('{0}{1}', variables('saprefix'), copyIndex())]",
"location": "[resourceGroup().location]",
"sku": {
"name": "Standard_LRS"
},
"kind": "StorageV2",
"copy": {
"name": "storageAccountLoop",
"count": "[variables('numberOfAccounts')]"
}
},
{
"type": "Microsoft.Storage/storageAccounts/blobServices",
"apiVersion": "2021-08-01",
"name": "[format('{0}{1}/default', variables('saprefix'), copyIndex())]",
"copy": {
"name": "blobServiceLoop",
"count": "[variables('numberOfAccounts')]"
},
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts', format('{0}{1}', variables('saprefix'), copyIndex()))]"
]
},
{
"type": "Microsoft.Storage/storageAccounts/blobServices/containers",
"apiVersion": "2021-08-01",
"name": "[format('{0}{1}/{2}/{3}{4}', variables('saprefix'), mod(copyIndex(), variables('numberOfAccounts')), 'default', 'container', mod(copyIndex(), variables('blobsPerAccount')))]",
"copy": {
"name": "containerLoop",
"count": "[mul(variables('numberOfAccounts'), variables('blobsPerAccount'))]"
},
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts', format('{0}{1}', variables('saprefix'), mod(copyIndex(), variables('numberOfAccounts'))))]",
"[resourceId('Microsoft.Storage/storageAccounts/blobServices', format('{0}{1}', variables('saprefix'), mod(copyIndex(), variables('numberOfAccounts'))), 'default')]"
]
}
]
}
有帮助吗?