Azure Resource Manager

Terminology

  • Resource: Any thing which you want to provision in your Azure Subscription (eg. VirtualMachines, Virtual Network, Storage Account, Service Fabric etc.)
  • Resource Group: A container that holds resources Refer here
  • Resource Provider: This is responsible for creating and manager resources. There are many resource providers in azure. Refer here
  • Subscription: The Azure account is a unique entity that gets you access to Azure services and your Azure subscriptions. You can create multiple subscriptions in your Azure account to create separation In your subscription(s) you can manage resources in resources groups.
  • Resource Manager template: A Json file that defines infrastructure and configuration of the azure solution that you can repeatedly deploy & get the consistent state always.

Find Registered Providers in your subscription

Core Structure of ARM Template

The core structure of arm template is as follows

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "",
    "parameters": {  },
    "variables": {  },
    "functions": [  ],
    "resources": [  ],
    "outputs": {  }
}
  • $schema : Json Schema defining the structure of template. This has two values
  1. for resource group deployments use https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#
  2. for subscription deployments use https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#
  • contentVersion : current template version maintained
  • parameters : Values to be provided which ARM cannot workout (for eg: Name of the vm)
  • variables : Values that can be reused which ARM can workout on its own (for eg: resourceId of the VM)
  • functions : User defined functions for using with in the template
  • resources : resources that needs to be deployed
  • outputs : values returned post deployment

Template Limits

Following are the limits of the ARM Template

  • Size of the template : 1 MB
  • each parameter file : 64 KB
  • maximum number of parameters that can be defined : 256
  • maximum number of variables that can be defined : 256
  • maximum number of resources that can be defined : 800
  • maximum number of outputs that can be defined : 64
  • maximum number of characters in template expression : 24576

Writing Basic ARM Templates

Steps to Simplify ARM Template Creation

  • First and foremost step for writing template is to understand the resources which you are trying to create. For the people who are trying to create your first template ensure you do it manually on the azure portal/azure cli/azure powershell and make a note of all the different inputs which you are passing
  • Set up Editors:
  • Create a new directory and open the directory in your favorite editor. (In this demonstration i would be using visual studio code). Create a file named myfirstarm.json
  • As an example i would be creating azure vnet. Refer Create Virtual Network Section here
  • Copy the following code into the myfirstarm.json file
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "",
    "parameters": {  },
    "variables": {  },
    "functions": [  ],
    "resources": [  ],
    "outputs": {  }
}
  • content version will be 1.0.0.0 for my reference
  • I will not be using any variables, functions, parameters & outputs in this example. So will remove these sections as all of them are optional fields
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "resources": [  ]
}
  • The basic structure of the resource can be referred over here
  • Since i need to create a virtual network which is a resource. I would be referring to the azure documentation to write basic virtual network resource.
  • Navigate to here
  • On the menu present on the left side find Network and expand all resources

  • Find virtualNetworks and choose api version and get into property values section.
  • In the resources section of the json create a json object and identify the properties that you need to create. As mentioned above in this example i referred to use the following values
Name: myVirtualNetwork.
Address space: 10.1.0.0/16.
Location: East US.
Subnet - Name : myVirtualSubnet.
Subnet - Address range:  10.1.0.0/24.
  • Create a network with name
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "resources": [
        {
            "name" : "myVirtualNetwork",  //From our requirement
            "type": "Microsoft.Network/virtualNetworks", //From documentation (resource type)
            "apiVersion": "2018-08-01", //From documentation
            "location": "East Us" // From our requirement,
            "properties: {
                //For setting network specific values and as mentioned in documentation it is object as mentioned over https://docs.microsoft.com/en-us/azure/templates/microsoft.network/2018-08-01/virtualnetworks#VirtualNetworkPropertiesFormat
                "addressSpace": {
                    //This is also object which has following structure as mentioned here https://docs.microsoft.com/en-us/azure/templates/microsoft.network/2018-08-01/virtualnetworks#AddressSpace
                    "addressPrefixes" : ["10.1.0.0/16"],
                    "subnets": [ //Refer https://docs.microsoft.com/en-us/azure/templates/microsoft.network/2018-08-01/virtualnetworks#Subnet
                        {
                            "name": "myVirtualSubnet",
                            "properties": { // Refer https://docs.microsoft.com/en-us/azure/templates/microsoft.network/2018-08-01/virtualnetworks#SubnetPropertiesFormat
                                "addressPrefix": "10.1.0.0/24"
                            }

                        }
                    ]

                }

            }


        }
     ]
}
  • Thats it we have finished creation of our template.
  • We need to execute this to create a deployment

Execute the Template to create a deployment

  • create a resource group
    • CLI:
      az group create –name armfromcli
    • Powershell:

    • New-AzureRmResourceGroup –name armfromps
  • create a deployment
    • CLI: az group deployment create –name depfromcli –resource-group armfromcli –template-file “myfirstarm.json”
    • Powershell:
      New-AzureRmResourceGroupDeployment -Name depfromps -ResourceGroupName armfromps -TemplateFile “myfirstarm.json”

One thought on “Azure Resource Manager

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About continuous learner

devops & cloud enthusiastic learner