4

I have created a bicep template to create two storage accounts. How to create a container within the storage accounts.

param rgLocation string = resourceGroup().location
param storageNames array = [
  'storage1'
  'storage2'
]

resource createStorages 'Microsoft.Storage/storageAccounts@2021-06-01' = [for name in storageNames: {
  name: '${name}str${uniqueString(resourceGroup().id)}'
  location: rgLocation
  sku: {
    name: 'Standard_LRS'
  }
  kind: 'StorageV2'
}]
Thomas
  • 24,234
  • 6
  • 81
  • 125
tommyt
  • 309
  • 5
  • 15

1 Answers1

8

You would need an additional loop to create a container per storage:

param rgLocation string = resourceGroup().location
param storageNames array = [
  'storage1'
  'storage2'
]

param containerName string = 'container1'

// Create storages
resource storageAccounts 'Microsoft.Storage/storageAccounts@2021-06-01' = [for name in storageNames: {
  name: '${name}str${uniqueString(resourceGroup().id)}'
  location: rgLocation
  sku: {
    name: 'Standard_LRS'
  }
  kind: 'StorageV2'
}]

// Create blob service
resource blobServices 'Microsoft.Storage/storageAccounts/blobServices@2019-06-01' = [for i in range(0, length(storageNames)): {
  name: 'default'
  parent: storageAccounts[i]
}]

// Create container
resource containers 'Microsoft.Storage/storageAccounts/blobServices/containers@2019-06-01' = [for i in range(0, length(storageNames)): {
  name: containerName
  parent: blobServices[i]
  properties: {
    publicAccess: 'None'
    metadata: {}
  }
}]
Thomas
  • 24,234
  • 6
  • 81
  • 125
  • Containers don't seem to support a Resource `tag` but rather `Metadata`. How would you add `metadata` to the Containers in Bicep? – ericOnline Oct 28 '22 at 18:31
  • Disregard :) Found the [docs](https://learn.microsoft.com/en-us/azure/templates/microsoft.storage/storageaccounts/blobservices/containers?pivots=deployment-language-bicep#containerproperties) – ericOnline Oct 28 '22 at 20:14