Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bicep template create containers within a storage account

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'
}]

1 Answers

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: {}
  }
}]
like image 113
Thomas Avatar answered Sep 19 '25 06:09

Thomas