ARM Templates has various dynamic constructs called Helper Functions which can make your template more generic. These constructs reduce the hard coded values in your templates. You can use the information from this blog to make your existing templates more dynamic and start writing new templates with a much generic approach.
Let’s look at the most important helper functions and their practical usage one by one.
1. Resource Id – Resource Function
You use this function to determine the ID of a resource. This is only used when the resource (whose ID is needed) is not being deployed in the current template and it already exists in Azure.
The generic syntax to use this is:
<span class="hljs-tag">resourceId</span> (<span class="hljs-attr_selector">[subscriptionId]</span>, <span class="hljs-attr_selector">[resourceGroupName]</span>, <span class="hljs-tag">resourceType</span>, <span class="hljs-tag">resourceName1</span>, <span class="hljs-attr_selector">[resourceName2]</span>...)
Only required parameters of this helper function are resourceType and resourceName1.
These parameters are as follows:
- subscription ID – This is only needed if you want to refer a different subscription. Default value is the current subscription
- resource Group Name – Name of the resource group where the resource exists. Default is the current resource group, in which you are deploying the template
- resource Type – Type of resource including resource provider namespace
- resource Name 1 – Name of the resource
- resource Name 2 – Next resource name segment if resource is nested. E.g. a VM Extension