Custom functions in Azure ARM Templates

Azure provides a helpful number of functions which can be used in ARM templates. It makes our life easier.

We can see the complete list of Azure ARM function here

Apart from that in some situations, you may find your self where you need to implement custom function inside ARM templates. So we can reuse it. So it is DRY.

Typically, we use complicated logic inside the function that we don’t want to duplicate in the ARM template.

So is it possible in ARM template? Yes, ARM templates give us the opportunity to implement custom functions. šŸ™‚

Keep in mind. There are some restrictions when we use functions as below.

  • The function can’t access variables.
  • The function can only use parameters that are defined in the function. When you use theĀ parameters functionĀ within a user-defined function, you’re restricted to the parameters for that function.
  • The function can’t call other user-defined functions.
  • The function can’t use theĀ reference function.
  • Parameters for the function can’t have default values

The custom function should be declared inside functions property in an ARM template.

Following is a sample function which accepts the container name as a parameter and appends resource group location to container name.

Note that parameters used in scope of function should be declared in parameters section in ARM template.

Your functions require a namespace value to avoid naming conflicts with template functions. In above function we have used rt as namespace.

 

Then we can call the function as below

rt.containerNameWithLocation(parameters(‘containerName’))

Following snippet shows actual usage of this function.

 

So enjoy writing custom functions in ARM Template šŸ™‚

Advertisements

I am a passionate software developer. I develop software using microsoft technologies and other trending web technologies. currently works at sitecore as a developer

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s