You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Modules and loops are essential features for building maintainable, DRY (Don't Repeat Yourself) Bicep templates. Modules break large templates into reusable components, while loops create multiple resources from a single definition.
A module is a Bicep file that is consumed by another Bicep file. Modules enable:
A module is simply a regular Bicep file. For example, a storage account module:
modules/storage.bicep
@description('Name of the storage account')
param storageAccountName string
@description('Azure region')
param location string = resourceGroup().location
@description('Storage SKU')
@allowed(['Standard_LRS', 'Standard_GRS', 'Standard_ZRS'])
param skuName string = 'Standard_LRS'
@description('Tags to apply')
param tags object = {}
resource storageAccount 'Microsoft.Storage/storageAccounts@2023-01-01' = {
name: storageAccountName
location: location
sku: {
name: skuName
}
kind: 'StorageV2'
properties: {
minimumTlsVersion: 'TLS1_2'
supportsHttpsTrafficOnly: true
allowBlobPublicAccess: false
}
tags: tags
}
output storageAccountId string = storageAccount.id
output primaryBlobEndpoint string = storageAccount.properties.primaryEndpoints.blob
output name string = storageAccount.name
main.bicep
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.