Sometimes, when we are creating multiple resources, some of the resources have dependencies on the other resources. For example, we cannot create blob storage, until we create storage account Or we cannot really create a database until we have a logical SQL server. This implies that we should order the creation of resource in such a way that dependent resources are created after the independent resources.
In this article, we are going to have a look at how to specify resource dependencies in the bicep file.
How the resources are deployed ?
Azure resource manager resolves the dependencies among the resources being deployed. The resources are always deployed in their dependency order. The resources which are not dependent on each other are created in parallel.
The order of dependency can be determined by two ways – implicit dependencies or explicit dependencies.
As the name suggests, no extra syntax needed for denoting such dependencies. When a bicep file has a resource which uses properties of other resource from the same file, it automatically sets the implicit dependency. Also, a nested resource has implicit dependency on its parent.
The code snippet given below shows an example of implicit dependency.
An explicit dependency can be set by adding a dependsOn attribute in a resource. This property takes an array of symbolic names of the resources on which current resource is dependent.
It is generally recommended by documentation that
- We should not need to setup an explicit dependency. Most of the times, implicit dependencies should be sufficient to achieve the intended result.
- If there is a need of explicit dependency, we should try to imply the dependency by specifying the symbolic name of the resource.
- Otherwise we should refactor the bicep template to avoid explicit dependency.
I hope you find this information helpful. Let me know your thoughts.