Course contentsShow
← Cloud and Infrastructure
Lesson 900 of 2,98917. Azure ARM Templates and BicepFree lesson

Resource Dependencies and Ordering

Control deployment order using dependsOn to ensure resources are created in the correct sequence.

Resource Dependencies and Ordering

You'll learn how to explicitly control which Azure resources are deployed before others using dependsOn to ensure your infrastructure is created in the correct sequence.

Why Order Matters

When deploying infrastructure, some resources must exist before others can be created. For example, a virtual machine needs a network interface, which in turn needs a virtual network. Azure usually infers these dependencies automatically from property references, but sometimes you need to manually specify the order.

The dependsOn Property

The dependsOn property in an ARM template explicitly tells Azure: "Don't create this resource until these other resources are finished." It takes an array of resource identifiers.

Basic syntax:

{
  "type": "Microsoft.Compute/virtualMachines",
  "name": "myVM",
  "dependsOn": [
    "[resourceId('Microsoft.Network/networkInterfaces', 'myNIC')]"
  ],
  "properties": { ... }
}

When to Use dependsOn

Use explicit dependencies when:

  • Azure can't infer the relationship from template references
  • One resource must complete before another starts, but you don't reference its properties
  • You need to enforce sequential creation for configuration or initialization reasons

Think of it like assembling furniture: you wouldn't attach the tabletop before screwing in the legs. dependsOn ensures your "legs" are ready before the "tabletop" is installed.

Implicit vs Explicit

Azure automatically creates implicit dependencies when you reference another resource's output or property. Explicit dependsOn is for cases where no reference exists in your template but the logical dependency still matters.

Key Takeaway: Use dependsOn to explicitly control deployment order when Azure can't automatically infer resource dependencies from template references, ensuring your infrastructure components are created in the correct sequence.