Hi All,
One of the projects I’m working on, includes building ARM templates that are going to be used (hopefully without alteration) for a long time. As the API versions get updated, it is worth staying up to date while retaining the ability to use a known good version. This may sound tricky to do in a single template, but it s simpler than it appears.
The API versions for each resource type can be displayed by this command:
get-AzureRmResourceProvider | %{$Provider = $_.ProviderNameSpace;$_ | select -expand ResourceTypes | select -Property @{N=”Provider”;E={$Provider}},ResourceTypeName,APIVersions}
An adaptation of the Quickstart Windows VM template with these modifications is displayed below. I have highlighted the changed lines.
{ "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "adminUsername": { "type": "string", "metadata": { "description": "Username for the Virtual Machine." } }, "adminPassword": { "type": "securestring", "metadata": { "description": "Password for the Virtual Machine." } }, "dnsLabelPrefix": { "type": "string", "metadata": { "description": "Unique DNS Name for the Public IP used to access the Virtual Machine." } }, "windowsOSVersion": { "type": "string", "defaultValue": "2016-Datacenter", "allowedValues": [ "2008-R2-SP1", "2012-Datacenter", "2012-R2-Datacenter", "2016-Nano-Server", "2016-Datacenter-with-Containers", "2016-Datacenter" ], "metadata": { "description": "The Windows version for the VM. This will pick a fully patched image of this given Windows version." } }, "apiVersionChoice": { "type": "string", "defaultValue": "latest", "allowedValues": [ "latest", "known" ] } }, "variables": { "storageAccountName": "[concat(uniquestring(resourceGroup().id), 'elestest')]", "nicName": "myVMNic", "addressPrefix": "10.0.0.0/16", "subnetName": "Subnet", "subnetPrefix": "10.0.0.0/24", "publicIPAddressName": "myPublicIP", "vmName": "SimpleWinVM", "virtualNetworkName": "MyVNET", "subnetRef": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('virtualNetworkName'), variables('subnetName'))]", "APIVersionsRef": { "latest": { "storageAccounts": "[providers('Microsoft.Storage','storageAccounts').apiVersions[0]]", "publicIPAddresses": "[providers('Microsoft.Network','publicIPAddresses').apiVersions[0]]", "virtualNetworks": "[providers('Microsoft.Network','virtualNetworks').apiVersions[0]]", "networkInterfaces": "[providers('Microsoft.Network','networkInterfaces').apiVersions[0]]", "virtualMachines": "[providers('Microsoft.Compute','virtualMachines').apiVersions[0]]" }, "known": { "storageAccounts": "2015-06-01", "publicIPAddresses": "2016-03-30", "virtualNetworks": "2016-03-30", "networkInterfaces": "2016-03-30", "virtualMachines": "2015-06-15" } }, "APIVersions": "[variables('APIVersionsRef')[parameters('apiVersionChoice')]]" }, "resources": [ { "type": "Microsoft.Storage/storageAccounts", "name": "[variables('storageAccountName')]", "apiVersion": "[variables('APIVersions').storageAccounts]", "location": "[resourceGroup().location]", "sku": { "name": "Standard_LRS" }, "kind": "Storage", "properties": {} }, { "apiVersion": "[variables('APIVersions').publicIPAddresses]", "type": "Microsoft.Network/publicIPAddresses", "name": "[variables('publicIPAddressName')]", "location": "[resourceGroup().location]", "properties": { "publicIPAllocationMethod": "Dynamic", "dnsSettings": { "domainNameLabel": "[parameters('dnsLabelPrefix')]" } } }, { "apiVersion": "[variables('APIVersions').virtualNetworks]", "type": "Microsoft.Network/virtualNetworks", "name": "[variables('virtualNetworkName')]", "location": "[resourceGroup().location]", "properties": { "addressSpace": { "addressPrefixes": [ "[variables('addressPrefix')]" ] }, "subnets": [ { "name": "[variables('subnetName')]", "properties": { "addressPrefix": "[variables('subnetPrefix')]" } } ] } }, { "apiVersion": "[variables('APIVersions').networkInterfaces]", "type": "Microsoft.Network/networkInterfaces", "name": "[variables('nicName')]", "location": "[resourceGroup().location]", "dependsOn": [ "[resourceId('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]", "[resourceId('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]" ], "properties": { "ipConfigurations": [ { "name": "ipconfig1", "properties": { "privateIPAllocationMethod": "Dynamic", "publicIPAddress": { "id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]" }, "subnet": { "id": "[variables('subnetRef')]" } } } ] } }, { "apiVersion": "[variables('APIVersions').virtualMachines]", "type": "Microsoft.Compute/virtualMachines", "name": "[variables('vmName')]", "location": "[resourceGroup().location]", "dependsOn": [ "[resourceId('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]", "[resourceId('Microsoft.Network/networkInterfaces/', variables('nicName'))]" ], "properties": { "hardwareProfile": { "vmSize": "Standard_A2" }, "osProfile": { "computerName": "[variables('vmName')]", "adminUsername": "[parameters('adminUsername')]", "adminPassword": "[parameters('adminPassword')]" }, "storageProfile": { "imageReference": { "publisher": "MicrosoftWindowsServer", "offer": "WindowsServer", "sku": "[parameters('windowsOSVersion')]", "version": "latest" }, "osDisk": { "name": "osdisk", "vhd": { "uri": "[concat(reference(resourceId('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))).primaryEndpoints.blob, 'vhds/osdisk.vhd')]" }, "caching": "ReadWrite", "createOption": "FromImage" }, "dataDisks": [ { "name": "datadisk1", "diskSizeGB": "100", "lun": 0, "vhd": { "uri": "[concat(reference(resourceId('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))).primaryEndpoints.blob, 'vhds/datadisk1.vhd')]" }, "createOption": "Empty" } ] }, "networkProfile": { "networkInterfaces": [ { "id": "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName'))]" } ] }, "diagnosticsProfile": { "bootDiagnostics": { "enabled": "true", "storageUri": "[reference(resourceId('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))).primaryEndpoints.blob]" } } } } ], "outputs": { "hostname": { "type": "string", "value": "[reference(variables('publicIPAddressName')).dnsSettings.fqdn]" } } }
As usual for any of my blog posts – if you have any feedback about any of the above, please provide it – that’s how I learn.