ARM Template function resourceId

While working on IaC templating for an Azure Application Gateway, I stumbled upon a to me different use of the resourceId function. Will try to explain how and what in this post.

My resourceId started out like this, mostly because I exported the application gateway resource template from the portal.

[concat(resourceId('Microsoft.Network/applicationGateways', 'appGatewayName'), '/probes/probeName')]

Because my build pipeline runs ARM TTK (more about that here), the templates are tested against a default test set before being accepted. One of these tests check for how IDs are built. Using concat to build an ID is considered a bad practice, therefore the build will fail.

Everyone who has used the resourceId function knows the basic syntax:

resourceId([subscriptionId], [resourceGroupName], resourceType, resourceName1, [resourceName2], ...)

What I was not aware of, and now I see this is noted in the documentation, was how to get the id of child resources. I was trying to get the resource id like this:

[resourceId('Microsoft.Network/applicationGateways', 'appGatewayName', 'probes', 'probeName')]

…but could only get an error message:

the type ‘’ requires ‘1’ resource name argument(s)

Blind as I sometimes am when troubleshooting an issue like this, I did not see the answer right before my eyes. After looking at the resourceId reference documentation, I still could not understand how it worked. In hindsight I should have read the docs more closely…

Some web searching led me to this answer on stackoverflow. This is similar to my issue, and pointed me in the direction of where my solution was.

Ended up with the following resourceId structure:

[resourceId('Microsoft.Network/applicationGateways/probes', 'appGatewayName', 'probeName')]

[resourceId('Microsoft.Network/applicationGateways/backendAddressPools', 'appGatewayName', 'backendAddressPoolName')]

[resourceId('Microsoft.Network/applicationGateways/Microsoft.Network/applicationGateways/backendHttpSettingsCollection', 'appGatewayName', 'backendHttpSettingsName')]

This is maybe very basic for some, and could potentially save a headache for others. The answer on stackoverflow at least helped me, and maybe this post can help someone else.

One Reply to “ARM Template function resourceId”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.