Looking to get some guidance and explanation around dependsOn
.
I have seen in templates there are two methods of providing dependencies in a template.
One method is to provide resourceId
and the other method is to provide a string value using concat
. I'm trying to understand the difference between the two.
Example
[concat('Microsoft.Network/networkInterfaces/', variables('networkInterfaceName'))]
and also on some examples, this is referenced with resourceId
:
[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachineName'))]
I am looking to understand the difference and also in which scenarios we should use concat
to reference dependencies and where we can use resourceID
.
The real difference between when you use resourceId or not (in dependsOn) is this: Is the resource you depend on in the same template? If so, you can simply just have the name. For example, here is a load balancer, which depends on a public IP and a vNet that are created in the same template:
"apiVersion": "[variables('lbApiVersion')]",
"type": "Microsoft.Network/loadBalancers",
"name": "[variables('lbName1')]",
"location": "[variables('computeLocation')]",
"dependsOn": [
"[variables('lbIPName1')]",
"[variables('virtualNetworkName')]"
],
"properties": {
"frontendIPConfigurations": [
{
"name": "LoadBalancerIPConfig",
"properties": {
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('lbIPName1'))]"
}
If you are referencing a resource from outside the template, then you need resourceId. This is not needed with dependsOn, as you can only depend on resources that are in the same template. Where it is needed in my example, is the publicIPAddress id. This property needs a full resource Id, which is what the resourceId function provides. So the question becomes, does that property need a full resource Id?