Bicep Modules
What you'll learn: How to package Bicep code into reusable modules that you can share across deployments and projects.
What Are Bicep Modules?
Think of Bicep modules like recipe cards in cooking. Instead of writing out all the instructions for "making pasta" every time you create a new dish, you reference your pasta recipe card. Similarly, modules let you encapsulate common infrastructure patterns (like a storage account with specific settings) into a separate file and reuse it across multiple deployments.
Creating a Module
A module is simply a Bicep file containing resources you want to reuse. Save it as a .bicep file:
// storage-module.bicep
param location string
param storageName string
resource storageAccount 'Microsoft.Storage/storageAccounts@2021-06-01' = {
name: storageName
location: location
sku: {
name: 'Standard_LRS'
}
kind: 'StorageV2'
}
Consuming a Module
To use your module, reference it in another Bicep file using the module keyword:
// main.bicep
param location string = 'eastus'
module storage 'storage-module.bicep' = {
name: 'storageDeployment'
params: {
location: location
storageName: 'mystorageacct123'
}
}
The name property defines the deployment name in Azure, while params passes values to your module's parameters—just like calling a function with arguments.
Why Use Modules?
Modules reduce duplication, enforce consistency, and make templates easier to understand. When you need to update a pattern (like security settings), you change one module file instead of hunting through dozens of templates.
Key Takeaway: Bicep modules are reusable .bicep files that encapsulate infrastructure patterns and can be consumed by other templates using the module keyword with parameters.