Modules and dependencies¶
A typed interface¶
A Bicep module is a reusable template with parameters, outputs, and deployment scope. A local relative path resolves from the calling Bicep file, not from your terminal's working directory. Use small, meaningful contracts instead of a large collection of unrelated flags.
The foundation is an actual caller:
targetScope = 'subscription'
@description('Short naming prefix; no credentials or identifiers belong here.')
@minLength(2)
@maxLength(12)
param prefix string = 'learn'
@description('Environment label; use a dedicated group per environment.')
@allowed([
'dev'
'test'
'prod'
])
param environment string = 'dev'
@description('Approved region; deployment metadata region is provided through Azure CLI.')
param location string = 'eastus2'
@description('Globally unique lowercase alphanumeric storage account name.')
@minLength(3)
@maxLength(24)
param storageAccountName string
var baseName = '${toLower(prefix)}-${environment}'
var commonTags = {
environment: environment
purpose: 'bicep-overview'
}
resource group 'Microsoft.Resources/resourceGroups@2025-04-01' = {
name: 'rg-${baseName}'
location: location
tags: commonTags
}
module network '../../modules/isolated-network/main.bicep' = {
name: 'network-${environment}'
scope: group
params: {
virtualNetworkName: '${baseName}-vnet'
location: location
tags: commonTags
}
}
module storage '../../modules/private-storage/main.bicep' = {
name: 'storage-${environment}'
scope: group
params: {
storageAccountName: storageAccountName
location: location
tags: commonTags
}
}
@description('Group to inspect and, for a disposable lab, delete after verification.')
output resourceGroupName string = group.name
@description('Network module result.')
output virtualNetworkId string = network.outputs.virtualNetworkId
@description('Storage module result; not data access or a credential.')
output storageAccountId string = storage.outputs.storageAccountId
The root creates a group and sets scope: group on each module.
The group reference establishes the scope/dependency; module output
references let downstream callers consume results without duplicating names.
The caller supplies shared location/tags consistently.
Included contracts¶
| Module | Responsibility | Not included |
|---|---|---|
| Private storage | Private-only StorageV2 account | Endpoint, DNS, data roles, containers, backup |
| Isolated network | VNet/subnet and attached deny-inbound NSG | Workload allows, egress policy, NAT, compute |
Both are resource-group-scoped and independently compilable. Neither is certified production infrastructure.
Registry modules¶
Bicep also supports registry module references. Pin a reviewed version/tag, record provenance/license, and inspect inputs, outputs, API versions, source, and permissions. Restoring a registry module may need network/authentication; local examples here avoid those extra prerequisites. Do not assume a tag is immutable unless the registry's policy guarantees it.
Consider Azure Verified Modules and the Bicep for Everyone catalog for broader building blocks with their own maintenance/support policies.
Scope and ownership review¶
Give each resource a clear owning template/team. Do not combine two modules that both redefine the same VNet/subnets with different intended properties. Review complete arrays and full resource declarations when composing network templates; "incremental" does not mean every property list is merged safely. Prefer references to existing shared resources where ownership lies elsewhere.
Exercise: add a non-sensitive ownership tag at the foundation root, trace its propagation to both modules, then compile and inspect the generated templates.