ARM Template
ARM stands for Azure Resource Manager. We use ARM templates to deploy resources to Azure. We can automate deployments and use the infrastructure as code. In code, we define the infrastructure that needs to be deployed. The infrastructure code becomes part of our project. Like the application code, we store the infrastructure code in a repository and version it. We use this approach because anyone on the team can run the code and deploy similar environments.
To implement infrastructure as code for Azure solutions, we use Azure Resource Manager (ARM) templates. The template is a JSON file that defines the infrastructure and configuration. In the template, we specify the resources to deploy and the properties for those resources. The template uses declarative syntax, which lets you deploy without having to write the sequence of programming commands to create it.
Template file
The template has the following sections,
- Parameters- We can provide values during deployment that allow the same template to be used for different Environments.
- Variables- These values can be reused in templated and can be formed from parameter values.
- User-defined functions- Create functions that simplify our template.
- Resources- Resources that are to be deployed
- Outputs- Return values from the deployed resources.
Below is a sample template file that creates a Storage Account, Azure App Service Plan & Web App.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters":{
"storagePrefixForArm":{
"type": "string",
"minLength": 3,
"maxLength": 24
},
"appServicePlanName": {
"type": "string",
"defaultValue": "exampleplan1"
},
"location":{
"type": "string",
"defaultValue": "[resourceGroup().location]"
},
"webAppName": {
"type": "string",
"metadata": {
"description": "web app name and app service plan "
},
"minLength": 2
},
"linuxFxVersion": {
"type": "string",
"defaultValue": "php|7.0",
"metadata": {
"description": "Current Web App"
}
},
"storageSKU":{
"type":"string",
"defaultValue": "Standard_LRS",
"allowedValues": [
"Standard_LRS",
"Standard_GRS",
"Standard_RAGRS",
"Standard_ZRS",
"Premium_LRS",
"Premium_ZRS",
"Standard_GZRS",
"Standard_RAGZRS"
]
},
"resourceTags": {
"type": "object",
"defaultValue": {
"Environment": "Dev",
"Project": "ARMTemp"
}
}
},
"variables":{
"uniqueStorageName":"[concat(parameters('storagePrefixForArm'),uniqueString(resourceGroup().id))]",
"webAppPortalName": "[concat(parameters('webAppName'), uniqueString(resourceGroup().id))]"
},
"resources": [{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2019-04-01",
"name": "[variables('uniqueStorageName')]",
"location": "[parameters('location')]",
"tags": "[parameters('resourceTags')]",
"sku": {
"name": "[parameters('storageSKU')]"
},
"kind": "StorageV2",
"properties": {
"supportsHttpsTrafficOnly": true
}
}, {
"type": "Microsoft.Web/serverfarms",
"apiVersion": "2016-09-01",
"name": "[parameters('appServicePlanName')]",
"location": "[parameters('location')]",
"sku": {
"name": "B1",
"tier": "Basic",
"size": "B1",
"family": "B",
"capacity": 1
},
"kind": "linux",
"properties": {
"perSiteScaling": false,
"reserved": true,
"targetWorkerCount": 0,
"targetWorkerSizeId": 0
}
}, {
"type": "Microsoft.Web/sites",
"apiVersion": "2018-11-01",
"name": "[variables('webAppPortalName')]",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName'))]"
],
"kind": "app",
"properties": {
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName'))]",
"siteConfig": {
"linuxFxVersion": "[parameters('linuxFxVersion')]"
}
}
}],
"outputs": {
"storageEndpoint": {
"type": "object",
"value": "[reference(variables('uniqueStorageName')).primaryEndpoints]"
}
}
}
Let's Deep dive into the template file for each section.
$schema
Specifies the location of the JSON schema file. The schema file describes the properties that are available within a template.
contentVersion
Specifies the version of the template you are creating, and value is used for versioning for the significant changes of your template.



Join the conversation! Your thoughts help the community grow.