Resource Dependencies in Bicep
What you'll learn: How Bicep automatically and explicitly manages the order in which Azure resources are created using symbolic references.
The Problem of Creation Order
When deploying infrastructure, some resources must exist before others can be created. For example, you can't create a virtual machine without first creating a virtual network. Just like building a house—you need a foundation before you can add walls.
Implicit Dependencies with Symbolic References
Bicep makes dependency management elegant through symbolic references. When you reference another resource's property in your code, Bicep automatically understands that resource must be created first.
resource vnet 'Microsoft.Network/virtualNetworks@2021-02-01' = {
name: 'myVNet'
location: 'eastus'
properties: {
addressSpace: {
addressPrefixes: ['10.0.0.0/16']
}
}
}
resource subnet 'Microsoft.Network/virtualNetworks/subnets@2021-02-01' = {
parent: vnet // Implicit dependency created here
name: 'mySubnet'
properties: {
addressPrefix: '10.0.1.0/24'
}
}
By using parent: vnet, Bicep knows the subnet depends on the virtual network. No extra configuration needed!
Explicit Dependencies with dependsOn
Sometimes resources don't directly reference each other, but still need a specific creation order. Use the dependsOn property:
resource storage 'Microsoft.Storage/storageAccounts@2021-04-01' = {
name: 'mystorageacct'
location: 'eastus'
kind: 'StorageV2'
sku: {
name: 'Standard_LRS'
}
dependsOn: [
vnet // Explicit dependency
]
}
This ensures the virtual network exists before the storage account is created, even though the storage account doesn't directly use it.
Key Takeaway: Bicep handles dependencies through symbolic references automatically (implicit), and you can add explicit dependencies with dependsOn when resources need specific ordering without direct property references.