Plantignum

Intro to ARM

Feeling tired of creating virtual machines, storage accounts, and app services in the Azure portal? Is your environment duplicated often and you need an easier method? Maybe you should write some ARM templates! Microsoft’s Azure Resource Manager, or ARM, provides deployment and management of Azure resources. Azure resources are created, updated, and deleted using the ARM management layer. We will discuss ARM templates, the components of writing a template.

ARM Templates in a nutshell #

An ARM template is a form of infrastructure as code, a concept where you define the infrastructure you need to deploy. Creating virtual machines and deploying storage accounts no longer require you to navigate the portal and start clicking. In contrast, the template defines resources, and Azure ARM creates the infrastructure based on the defined resources.

Declarative syntax lets you give a list of resources you want to create without stating exactly how they should be created. You can, for example, create a virtual machine using a script using Azure CLI or Azure PowerShell. You must, however, implement logic and error checks to handle any situation. Declarative templates specify the end state of an environment, and Azure uses the template as input to create the environment. If the resource doesn’t exist or if the template is different, the ARM management layer will create one. Many benefits can be derived from using ARM templates to manage your Azure environment. Since declarative syntax eliminates the need for complicated deployment scripts, it makes it easier to handle different deployment scenarios without writing complicated code.

The same template can be written and deployed multiple times to get the same result as ARM templates are repeatable. For the production environment, you can use the same template you used for the development environment. When you use the same template, the resources and settings are the same. Azure Resource Manager also controls the order of operations during deployment. Therefore, ARM deploys resources in a correct order and, where possible, deploys them in parallel to improve deployment speeds. For a complete end-to-end environment setup, deployment scripts written in PowerShell or Bash can also be added to the templates.

Now that you have a general understanding of ARM templates, it is time for you to learn how to write your first template. The templates include advanced features as well as JavaScript Object Notation (JSON) syntax. Below is a blank ARM template:

{

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

Functions: #

Within the ARM template, we have a section called functions. You can create complex expressions using functions that you don’t want to repeat throughout the template. ARM template functions are like other functions in other programming languages. Whenever you need them, you call them, pass them information, and they return a value.

Let’s say you need unique names for resources. By creating a function to generate the unique name, you do not have to copy and paste the same code and paste it.To call a function you need to mention the function name and function object you are calling and the variable that you want to pass.

Variables #

ARM templates are similar to other programming languages when it comes to variables. Throughout the template, variables are used to store values. You can create complicated expressions using variables the same way you can use functions, so you don’t have to repeat them in the template.

"variables": {

    "location": "eastus"

}

Parameters: #

You can use parameters to pass different values to the ARM template during deployment. For example, you can specify the name of resources or the region in which to host them. Template parameters make your template more dynamic and allow it to be used in a variety of different environments.

A parameter must have a name and a type at the very least. Strings, arrays, objects, integers, booleans, and secure strings, such as passwords, are all possible parameter types. In addition, the parameter can include a description of how to use it. You don’t have to provide a default value at runtime since you can include one, and you can define a set of allowed values. For a parameter value, the allowed values determine what a user can use.

"parameters": {

    "VMSize": {
        "type": "string",
        "metadata": {
            "description": "Virtual Machine SKU Size"
        },
        "allowedValues": [
            "Standard_D2_v4",
            "Standard_D4_v4",
            "Standard_D8_v4",
            "Standard_D16_v4"
        ]
    }
}

Resource Group: #

And last but not least, resources, arguably the most important part of the ARM template. Here you specify what resources to deploy with this template. A resource can range from a network security group up to a virtual machine, a storage account, or an Azure function.

"name": “<resource name>”, # Name for the resource. 
"type":"Microsoft.<resource provider>/<resourcetype>",  #The type of resource to               
                                                   deploy example Microsoft.Storage
                                                          >> for storage 
"apiVersion": "<api version>", #resource's API version determines 
                                what properties can be configured.
"location": "<location>",# An Azure region is where a resource is deployed

"dependsOn": [], #Azure deploys resources in accordance with dependencies. 

"properties": {} # The properties section of a deployed 
                  resource contains configuration information.

You can read more abot ARM at it’s official website : https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/overview

Conclusion: #

In addition to reusability and standardization, Azure infrastructure can be defined using code. ARM templates can be used for both initial deployment and ongoing management of resources. As your infrastructure is code, other automations can be introduced, such as Azure DevOps or GitHub Actions, which will automatically deploy infrastructure changes.

Hope you enjoyed reading it

Thank you

Powered by BetterDocs