Daniel's Tech Blog

Cloud Computing, Cloud Native & Kubernetes

Using the latest API version in your Azure Resource Manager templates

I got a bit tired of checking which API version is the latest one and modifying my API variables in my ARM templates. So I investigated and tested a little bit and found a solution on how to get the latest API version every time.

You can do this via the provider resource function in your ARM templates.

-> https://azure.microsoft.com/en-us/documentation/articles/resource-group-template-functions/#providers

Let me show you that in an example providing the API version for a storage account.

"apiVersion": "[providers('Microsoft.Storage','storageAccounts').apiVersions[0]]"

As stated in the documentation you have to define the provider namespace Microsoft.Storage first. Then you define the resource type storageAccounts and at the end you are referencing to the first position in the apiVersions array to get the latest supported API version.

The necessary information about provider namespace and resource type can be easily queried via PowerShell.

$Provider=Get-AzureRmResourceProvider|Out-GridView -PassThru
$Provider.ResourceTypes

API02API03

It is very comfortable to do this via the provider resource function, but keep in mind that this approach is a bit risky. Microsoft can change the schema for a new API version and then you have to fix your templates. Let me explain that in an example between the API version 2015-06-15 and 2016-01-01 of the storageAccounts resource type.

When you are using 2015-05-15 as the API version, the ARM template definition looks like the following one.

API04

The usage of API version 2016-01-01 then looks like the following one.

API01

As you can see it they are different, because Microsoft introduced with API version 2016-01-01 the new Azure cool blob storage functionalities and has changed the schema. So pay attention when you are receiving the latest API version automatically over the provider resource function.

Have a look at the following table for some common resources and how to receive the latest API version automatically.

Resource API call
Nested deployments providers(‘Microsoft.Resources’,’deployments’).apiVersions[0]
Virtual machines providers(‘Microsoft.Compute’,’virtualMachines’).apiVersions[0]
Virtual machines extensions providers(‘Microsoft.Compute’,’virtualMachines/extensions’).apiVersions[0]
Availability sets providers(‘Microsoft.Compute’,’availabilitySets’).apiVersions[0]
Virtual networks providers(‘Microsoft.Network’,’virtualNetworks’).apiVersions[0]
Network security groups providers(‘Microsoft.Network’,’networkSecurityGroups’).apiVersions[0]
Network interfaces providers(‘Microsoft.Network’,’networkInterfaces’).apiVersions[0]
Public IP addresses providers(‘Microsoft.Network’,’publicIPAddresses’).apiVersions[0]
Storage accounts providers(‘Microsoft.Storage’,’storageAccounts’).apiVersions[0]
WordPress Cookie Notice by Real Cookie Banner