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.

ResourceAPI call
Nested deploymentsproviders(‘Microsoft.Resources’,’deployments’).apiVersions[0]
Virtual machinesproviders(‘Microsoft.Compute’,’virtualMachines’).apiVersions[0]
Virtual machines extensionsproviders(‘Microsoft.Compute’,’virtualMachines/extensions’).apiVersions[0]
Availability setsproviders(‘Microsoft.Compute’,’availabilitySets’).apiVersions[0]
Virtual networksproviders(‘Microsoft.Network’,’virtualNetworks’).apiVersions[0]
Network security groupsproviders(‘Microsoft.Network’,’networkSecurityGroups’).apiVersions[0]
Network interfacesproviders(‘Microsoft.Network’,’networkInterfaces’).apiVersions[0]
Public IP addressesproviders(‘Microsoft.Network’,’publicIPAddresses’).apiVersions[0]
Storage accountsproviders(‘Microsoft.Storage’,’storageAccounts’).apiVersions[0]
Facebooktwittergoogle_pluslinkedinmail

Leave a Reply