Written by 5:27 am Cloud • 76 Comments

Start With Azure ARM Template

March 30, 2021 0 Abhijit Kakade Cloud

I am here again with a new topic on Azure to share with you. Today I have come with Azure ARM template. In my first article, I will share the fundamental details of ARM template. Possibly in the next few weeks, I will come up with an advanced ARM template topic. If you have any specific query regarding ARM template please post your comment here.

Azure Resource Manager

When you create an application or use any Azure service it is typically made up of a lot of other components just like a virtual machine, virtual network, Storage, Cache service, database service or else any other service.  These are not separate entities. You can see that these are all interdependent on each other.  Actually, Azure Resource Manager enables you to maintain and deploy all these resources in the group. This grouping helps you to maintain all related resources like tagging and deployment as per interdependency. In ARM you use Template to deploy all related resources in order and in a single click.

Overview of ARM Template

ARM template is simple JSON format template which defines the infrastructure and configuration of the Azure solution. You may be aware that before ARM template there was ‘Classic Mode’ of Deployment. We used to call API to create different resources. It used to call ‘ASM (Azure Service Management)’.

Structure of ARM Template

There are mainly 4 important sections in the Template as seen by the below parameters, variables, resources, and output.

  1. {
  2.     “$schema”: “”,
  3.     “contentVersion”: “”,
  4.     “parameters”: {  },
  5.     “variables”: {  },
  6.     “resources”: [  ],
  7.     “outputs”: {  }
  8. }
  • Parameters
    This section is where you define all your input parameters. Any value which you don’t want to be static you pass to template on call.
  • Variables
    This is a section where you will define all static value variables which you can use overall anywhere in the template.
  • Resources
    Collection of resources to be deployed.
  • Outputs
    If you want to return any particular value or list of variables then this section can be used as output.

$schema is actually a location of schema file which describes the version of the template language. This URL will be different as per different versions.

contentVersion = its version of the template, you can pass any value here by inversion. But while deploying this template it makes sure the correct template is going to be used.

Sample ARM template

This is one basic ARM template to create Azure Storage. It contains one input parameter named ‘storageAccountType’  (string) and the default value is ‘Standard_LRS’ (if this parameter is blank then it will use the default value). It has one variable ‘storageAccountName’. Instead of simple string, it contains a concert and unique string function to generate storage account name. In resource section one storage account is going to be created.

  1. {
  2.       “$schema”: “https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#”,
  3.       “contentVersion”: “”,
  4.       “parameters”: {
  5.         “storageAccountType”: {
  6.           “type”: “string”,
  7.           “defaultValue”: “Standard_LRS”,
  8.           “metadata”: {
  9.             “description”: “Storage Account type”
  10.           }
  11.         }
  12.       },
  13.       “variables”: {
  14.         “storageAccountName”: “[concat(uniquestring(resourceGroup().id), ‘standardsa’)]”
  15.       },
  16.       “resources”: [
  17.         {
  18.           “type”: “Microsoft.Storage/storageAccounts”,
  19.           “name”: “[variables(‘storageAccountName’)]”,
  20.           “apiVersion”: “2016-01-01”,
  21.           “location”: “[resourceGroup().location]”,
  22.           “sku”: {
  23.               “name”: “[parameters(‘storageAccountType’)]”
  24.           },
  25.           “kind”: “Storage”,
  26.           “properties”: {
  27.           }
  28.         }
  29.       ],
  30.       “outputs”: {
  31.           “storageAccountName”: {
  32.               “type”: “string”,
  33.               “value”: “[variables(‘storageAccountName’)]”
  34.           }
  35.       }
  36.     }


While defining any parameters you can add conditions on this parameter value and other properties. See the below example:

  1. “storagename”: {
  2.     “Type”: “string”,
  3.     “allowedValues”: [
  4.                 “storage1”,
  5.                 “storage2”,
  6.                 “storage3”
  7.             ],
  8.     “defaultValue”: “storage1”,
  9.     “minLength”: “2”,
  10.     “minLength”: “50”,
  11.   },
  • Default Value
    Default value is to be used if one is not provided.
  • minLength and maxLength
    The minimum length for the string or array type parameter.
  • Metadata
    Metadata for the parameter can be any valid JSON object
  • Allowed values
    Value can only be one of these values.
  • minValue and maxValueMinimum and Maximum value for the int type parameter.

There are a total of seven types of parameters you can pass to ARM template:

  1. “parameterValueTypes”: {
  2.             “type”: [
  3.                 “string”,
  4.                 “boolean”,
  5.                 “integer”,
  6.                 “number”,
  7.                 “object”,
  8.                 “array”,
  9.                 “null”
  10.             ]},

Type = “SecureString” / “SecureObject”

If you have any secured data like password or secret key then use parameter type ‘SecureString’. If you pass any sensitive data in JSON format use parameter type ‘SecureObject’. The main reason for using type secure string is Template parameter with ‘SecureString’ or ‘SecureObject’ types cannot be read after resource deployment.

Deploy ARM Template using PowerShell

While deploying any Azure resources using ARM template, ARM template should be on your local machine drive or somewhere on external storage but should be accessible via URL.

Using PowerShell to Deploy ARM template you need to follow below steps,

Here in the below example, we will deploy Azure storage account using ARM template. This template has only one Parameter ‘StorageAccountType’.

  1. Log in to your Azure Account.
  2. Select subscription in which resource group you want to deploy resources. (If you have multiple subscriptions)
    1. Select-AzureRmSubscription -SubscriptionName <yourSubscriptionName>
  1. You can create new Resource Group or can use existing resource group.
  2. There are two ways to pass parameters to ARM template, first is you can directly pass an object of all parameters (as below) or create parameter file and pass parameter file path.
    1. $tempparam = @{
    2.    “storageAccountType” = “Standard_LRS”
    3. }

New-AzureRmResourceGroupDeployment -Name “gla-dev1-d-rsg-demoarm” `

  • ResourceGroupName “rsgmidserver” `
  • TemplateUri “C:\AK\create_storage.json” `
  • TemplateParameterObject $tempparam

The command ‘New-AzureRmResourceGroupDeployment’  is used to deploy Azure resources. There are a few parameters which are needed for this command to pass:

Name Deployment Name, this can be used to check different deployment details in azure portal or using PowerShell command.
ResourceGroupName Name of the existing Resource group where you want to deploy resources.
TemplateUri URI of your Azure ARM Template
TemplateParameterObject An Object which contains all parameters of ARM template.
TemplateParameterFile <optional> You can create parameter file and pass file path.

Once you execute the above command it will show status ‘Deploying’ in ‘Deployment’ section of your resource group.

If deployment is successful it will return a complete message with Status and all input and output parameters like below.

Overview of Deployment

Now, if you check your resource group then it will have a new resource, ‘StorageAccount,’ in the resources list.

So this was a basic overview of ARM template. In the next article, we will see some advanced level features of ARM templates. Until then if you have any queries please add a comment here. Thank you all.

(Visited 48 times, 1 visits today)