Azure Resource Manager Template Overview

Azure resource manager is the modern deployment service for Azure resources. It is an IaaS helping to automate Azure resource management. The ARM service is responsible for creating, Updating, or Deleting Azure resources in your subscription.

You can create Azure resources in multiple ways like Azure Portal, Powershell, Azure CLI, Fluent SDK, or Azure Resource Manager called as ARM Template.

All resource management requests will use same pipeline for creating, deleting or updating resources, as shown in following picture.

Azure Resource Manager Template

Benefits of using ARM Template

  1. Centralized Management: You can manage all your resources irrespective of environment from same template. This is great help to orgnize all resources.
  2. Security: You can use Role Based Access Control and OAuth Authetication with ARM templates. ARM provides very granular control on each resource.
  3. Resource Deployment: With the help of ARM templates you can add or remove any resource any time and multiple time.
  4. Extensibility: With deployment scripts, you can add PowerShell or Bash scripts to templates. The deployment scripts helps set up complex resources during deployment.

Azure ARM Template

Azure Resource Manager (ARM) is a deployment and resource management service. It is an IaaS helping to automate Azure resource management. The ARM service is responsible for creating, Updating, or Deleting Azure resources in your subscription.

The benefit of using ARM templates is that you have the definition and structure of all the resources deployed in the Azure environment. The same template can be reused to deploy resources to different Subscriptions, resource groups, or regions. ARM templates are handy for backup recovery plans and continuous deployments.

The ARM template is a JavaScript Object Notation (JSON) file that defines the infrastructure and configuration for your project.  You can declare the objects, types, and properties in the ARM template file. It contains Schema, ContentVersion, Parameters, variables, functions, resources,  and outputs. 

The basic ARM template looks like

{
    "$schema": "https://schema.management.azure.com
        /schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "",  
    "parameters": {  },
    "variables": {  },
    "functions": [  ],
    "resources": [  ],
    "outputs": {  }
}
    
  1. Schema

    Schema explains the location and purpose of the JSON file and its version. Schema can be for Resource Group Management, Subscription group deployment, Tenant group deployment, etc.
  2. Content Version

    It is the version number that you can give to the template for versioning.
  3. Parameters

    You can provide values of resources like name, location, or tags while resource deployment is executing the template. It is not mandatory to have Parameters in the template.

    "parameters": {
        "storageAccountName-dev": {
            "type": "string",
            "minLength": 3,
            "maxLength": 24,
            "metadata": {
                "description": "Storage account name for development environment."
            }
        }        
    }
                        

  4. variables

    You can construct values of variables and use them in the template. It is very useful when you want to build complex value and use it in multiple locations.

    {    
        "parameters": {
            "storageAccountName": {
                "type": "string",
                "minLength": 3,
                "maxLength": 24,
                "metadata": {
                    "description": "Storage Account name."
                }
            },
            "env": {
                "type": "string",
                "defaultValue": "test",
                "allowedValues": [
                    "test",
                    "dev",
                    "qa",
                    "prod"
                ],
                "metadata": {
                    "description": "Environment name."
                }
            }
        },
        "variables": { 
            "storageAccountName": 
                "[concat( parameters('storageAccountName') , parameters('env') )]"
        },
        "resources": [
            {
                "name": "[variables('storageAccountName')]"            
            }
        ]
    }
                    
  5. functions

    Functions are useful to avoid the repetition of a complex expression.

    "functions": 
    [
    {
        "namespace": "GeeksStorage",
        "members": {
            "uniqueResourceName": {
                "parameters": [
                    {
                    "name": "prefix",
                    "type": "string"
                    }
                ],
                "output": {
                    "type": "string",
                    "value": "[concat(toLower(parameters('prefix')), 
                        uniqueString(resourceGroup().id))]"
                }
            }
        }
    }
    ],
    "resources": [
    {
        "name": "[GeeksStorage.uniqueResourceName('StorageAccountName')]",
        "type": "Microsoft.Storage/storageAccounts"
    }
    ]
                    
  6. resources

    In the resources section, you can define the resources with the required metadata.

    {
        "$schema": "https://schema.management.azure.com/
            schemas/2015-01-01/deploymentTemplate.json#",
        "contentVersion": "1.0.0.0",
        "resources": [
            {
                "type": "Microsoft.Storage/storageAccounts",
                "apiVersion": "2019-04-01",
                "name": "GeeksStorageDemo",
                "location": "centralus",
                "sku": {
                    "name": "Standard_LRS"
                },
                "kind": "StorageV2"
            }
        ]
    }
                    
  7. Output

    The output section can return the result of deployment.

    {
        "$schema": "https://schema.management.azure.com/
            schemas/2015-01-01/deploymentTemplate.json#",
        "contentVersion": "1.0.0.0",
        "resources": [
    
        ],
        "outputs": {
            "uniqueString": {
                "value": "[uniqueString(resourceGroup().id)]",
                "type": "string"
            }
        }
    }
                    

Speak your mind
Please login to post your comment!