Bicep loops
Last updated:
AZUREBICEP
for
keyword to create a loop- can loop based on:
- array [[202407191859 Bicep parameters|Bicep parameters]]
- based on number
for i in range(1,4)
- Access the iteration index
name: 'sqlserver-${i+1}'
- Filter items with loops
- using
:
andif
- using
for sqlServer in sqlServerDetails: if (sqlServer.environmentName == 'Production')
- Use nested loop, for example for creating subnets in a vnet
- We can create [[202407191900 Bicep variables|Bicep variables]] loops
- can also create output loops
Example
param storageAccountNames array = [
'saauditus'
'saauditeurope'
'saauditapac'
]
resource storageAccountResources 'Microsoft.Storage/storageAccounts@2021-09-01' = [for storageAccountName in storageAccountNames: {
name: storageAccountName
location: resourceGroup().location
kind: 'StorageV2'
sku: {
name: 'Standard_LRS'
}
}]