Azure Resource Manager templates

When you need to create a consist method where you want to give to the end-user, that is consuming resources on your cloud, the power of creating resource like virtual machines, but you want to control lot of the environment aspects, you should consider using ARM templates.

An Azure Resource Manager template contain JSON formatted definition of one or more Azure resources, along with parameters and variables that facilitate customizing their configuration. When creating, and working with resource templates, you should consider:

  • Which resources you are going to deploy.
  • Where your resources will be located.
  • Which version of the resource provider API you will be use.
  • Whether there are dependencies between resources.
  • When you will specify values of resource properties. While you can include these values in the template, in general, it is preferable to specify them during deployment via corresponding parameters.

Understanding the structure of a resource template

A resource template consists of the following sections:

{
   “$schema”: “http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#“,
   “contentVersion”: “”,
   “parameters”: {  },
   “variables”: {  },
   “resources”: [  ],
   “outputs”: {  }
}

The following table describes the sections in the code sample above.

Element name           Required Description
$schema Yes This is a URL representing the location of the JSON schema file, which describes the template language.
contentVersion Yes This can be any value that helps you keep track of changes to template content.
parameters No Parameters can be provided during deployment either interactively or via a parameter file to customize properties of deployed resources.
variables No Variables are typically used to convert values of parameters to the format that is required to set resource property values.
resources Yes These are resource that you want to create or modify as the result of the deployment.
outputs No These values are returned by the deployment.

The next topic discusses these sections in more detail.

The following code is an example of a complete template that deploys a web app and uses code from a .zip file to provision the app:

{
   “$schema”: “http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#“,
   “contentVersion”: “1.0.0.0”,
   “parameters”: {
     “siteName”: {
       “type”: “string”
     },
     “hostingPlanName”: {
       “type”: “string”
     },
     “hostingPlanSku”: {
       “type”: “string”,
       “allowedValues”: [
         “Free”,
         “Shared”,
         “Basic”,
         “Standard”,
         “Premium”
       ],
       “defaultValue”: “Free”
     }
   },
   “resources”: [
     {
       “apiVersion”: “2014-06-01”,
       “type”: “Microsoft.Web/serverfarms”,
       “name”: “[parameters(‘hostingPlanName’)]”,
       “location”: “[resourceGroup().location]”,
       “properties”: {
         “name”: “[parameters(‘hostingPlanName’)]”,
         “sku”: “[parameters(‘hostingPlanSku’)]”,
         “workerSize”: “0”,
         “numberOfWorkers”: 1
       }
     },
     {
       “apiVersion”: “2014-06-01”,
       “type”: “Microsoft.Web/sites”,
       “name”: “[parameters(‘siteName’)]”,
       “location”: “[resourceGroup().location]”,
       “tags”: {
         “environment”: “test”,
         “team”: “ARM”
       },
       “dependsOn”: [
         “[resourceId(‘Microsoft.Web/serverfarms’, parameters(‘hostingPlanName’))]”
       ],
       “properties”: {
         “name”: “[parameters(‘siteName’)]”,
         “serverFarm”: “[parameters(‘hostingPlanName’)]”
       },
       “resources”: [
         {

           “apiVersion”: “2014-06-01”,

           “type”: “Extensions”,
           “name”: “MSDeploy”,
           “dependsOn”: [
             “[resourceId(‘Microsoft.Web/sites’, parameters(‘siteName’))]”
           ],
           “properties”: {
             “packageUri”: “https://auxmktplceprod.blob.core.windows.net/packages/StarterSite-modified.zip“,
             “dbType”: “None”,
             “connectionString”: “”,
             “setParameters”: {
               “Application Path”: “[parameters(‘siteName’)]”
             }
           }
         }
       ]
     }
   ],
“outputs”: {
“siteUri”: {
“type”: “string”,
“value”: “[concat(‘http://’,reference(resourceId(‘Microsoft.Web/sites‘, parameters(‘siteName’))).hostNames[0])]”
}
}
}

Marcos Nogueira

With more than 18 years experience in Datacenter Architectures, Marcos Nogueira is currently working as a Principal Cloud Solution Architect. He is an expert in Private and Hybrid Cloud, with a focus on Microsoft Azure, Virtualization and System Center. He has worked in several industries, including Aerospace, Transportation, Energy, Manufacturing, Financial Services, Government, Health Care, Telecoms, IT Services, and Gas & Oil in different countries and continents. Marcos was a Canadian MVP in System Center Cloud & Datacenter Managenment and he has +14 years as Microsoft Certified, with more than 100+ certifications (MCT, MCSE, and MCITP, among others). Marcos is also certified in VMware, CompTIA and ITIL v3. He assisted Microsoft in the development of workshops and special events on Private & Hybrid Cloud, Azure, System Center, Windows Server, Hyper-V and as a speaker at several Microsoft TechEd/Ignite and communities events around the world.

Leave a Reply

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