bicep using if condition and for keyword

We can use if to control whether we should create a resource in bicep. For example, we have this code here and you can see we are using "if" to evaluate if we should be creating resources.

resource container 'Microsoft.Storage/
storageAccounts/blobServices/containers@2023-01-01' = if (deploy) {
  parent: blobService
  name: name
  properties: {
    publicAccess: 'None'
    metadata: {
      project: 'audit-2026'
    }
  }
}

And then we can use "for" to create multiple container, for example, here we are using for and looping our array called containers to create multiple container in our storage account.

param containers array = [
  'container1'
  'container2'
  'container3'
]

resource container 'Microsoft.Storage/
storageAccounts/blobServices/containers@2023-01-01' = [for name in containers: {
  parent: blobService
  name: name
  properties: {
    publicAccess: 'None'
    metadata: {
      project: 'audit-2026'
    }
  }
}]



Comments

Popular posts from this blog

vllm : Failed to infer device type

android studio kotlin source is null error

NodeJS: Error: spawn EINVAL in window for node version 20.20 and 18.20