Learn ARM Templates: Simplify Your Cloud Infrastructure

Azure is the preferred cloud service among both light and moderate cloud users at 66% and 70%, respectively. Offering numerous tools to their users, ARM is the ultimate choice for Azure management resources. Do you belong to an organization intrigued with Azure, or will you step into such a company?

Familiarity with the services is paramount, depending on the role. Understanding the Azure Resource Manager templates and associated details helps automate, manage, and simplify cloud infrastructure. This article will guide you through everything you need about ARM templates, helping you gain the expertise to optimize Azure environments. Scroll down to enlighten yourself.

Your solution for becoming a cloud expert is here! Join our Azure DevOps Solutions Expert Master’s Program and start your career in DevOps Solutions today!

What is Azure Resource Manager?

Azure Resource Manager (ARM) is a one-stop solution for managing Azure resources. It allows the efficient and structured creation, deployment and monitoring of Azure resources in the Azure cloud. ARM achieves resource organization and security through administrative tools like tags, locks, and access control. The resources discussed here include databases, web apps, virtual machines, network interfaces, storage accounts, etc.

Get Certified and Future-Proof Your Career

Microsoft Certified: Azure Administrator AssociateENROLL NOW
Get Certified and Future-Proof Your Career

What are ARM Templates?

Azure Resource Manager (ARM) Templates in Azure refers to the block of code responsible for developing the configuration and infrastructure of the project. They are the components of Azure’s Infrastructure as a Code (IaaC) strategy. The template uses declarative syntax in JavaScript Object Notation (JSON) to state and deploy resources in the Azure cloud.

Benefits of Using ARM Templates

Using the ARM template in Azure has several advantages. They include:

  • Infrastructure as a Code allows repeated and consistent versioning, automation, deployment, modularity, orchestration, reusability and other features.
  • Using templates lowers the chances of manual errors relative to other deployment methods.
  • The Azure Resource Manager templates are compatible with deployment scripts imported from Bash Scripts or PowerShell.
  • Azure policy, if used, remediates non-compliant resources.
  • The Azure ARM template allows the declaration of different types of resources.
  • They ease the deployment process by requiring only one command to deploy all resource settings.
  • Users can also check the detailed template preview, including creating or deleting template resources.
  • Azure ARM templates can be tested for functional reliability with the ARM template toolkit.
  • Their release can be automated through the integration with CI/CD tools.
  • There are numerous pre-built templates available for usage.
  • The templates can be created with authoring tools like Visual Studio Code, which comprises multiple language functions.
Kickstart your cloud journey with the Microsoft Azure Fundamentals AZ-900 Certification! This beginner-friendly course equips you with essential Azure knowledge, helping you understand core services and cloud concepts. Enroll today!

Understanding ARM Template

The components or format of the template comprises multiple key-value pairs written in JSON format. They include:

  • Schema: It includes the information on the location of the JSON file and the specific template language version to be used in the current template. It is of different types according to the reason for deployment, such as resource, subscription, management and tenant group deployment.
  • Content version: It indicates the Azure Resource Manager template version, which the user decides.

The schema and content version will be of the following format:

{

"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",

"contentVersion": "1.0.0",

"parameters":{},

"variables":{},

"functions":[],

"resources": [],

"outputs":{}

}

  • Parameters: These values ensure the template's flexibility for deployment in different environments and state the configuration. They comprise details like name, type, values and properties.

Here is how to write the parameters:

"parameters": {

  "adminUsername": {

    "type": "string",

    "defaultValue": "Admin",

    "metadata": {

      "description": "Username for the Virtual Machine."

    }

  },

  "adminPassword": {

    "type": "securestring",

    "metadata": {

      "description": "Password for the Virtual Machine."

    }

  }

}

  • Variables: It encompasses the different values in the template. Variables help simplify and shorten your template by allowing you to define reusable values.

The example of variables is:

"variables": {

  "nicName": "myVMNic",

  "addressPrefix": "10.0.0.0/16",

  "subnetName": "Subnet",

  "subnetPrefix": "10.0.0.0/24",

  "publicIPAddressName": "myPublicIP",

  "virtualNetworkName": "MyVNet"

}

  • Functions: It states the stepwise mention of the procedure to be followed when called in the template. The users write these to simplify the templates.

The functions can be defined as follows:

"functions": [

  {

    "namespace": "contoso",

    "members": {

      "uniqueName": {

        "parameters": [

          {

            "name": "namePrefix",

            "type": "string"

          }

        ],

        "output": {

          "type": "string",

          "value": "[concat(toLower(parameters('namePrefix')), uniqueString(resourceGroup().id))]"

        }

      }

    }

  }

]

  • Resources: This part will inform about the resources to be deployed. The resources are defined by type, name, location, version, properties, variables, and parameters (as needed).

Declare the resources as follows:

"resources": [

  {

    "type": "Microsoft.Network/publicIPAddresses",

    "name": "[variables('publicIPAddressName')]",

    "location": "[parameters('location')]",

    "apiVersion": "2018-08-01",

    "properties": {

      "publicIPAllocationMethod": "Dynamic",

      "dnsSettings": {

        "domainNameLabel": "[parameters('dnsLabelPrefix')]"

      }

    }

  }

]

  • Outputs: These are the results expected when running the template. The result will be depicted as follows:

"outputs": {

  "hostname": {

    "type": "string",

    "value": "[reference(variables('publicIPAddressName')).dnsSettings.fqdn]"

  }

}

Learn the Key Azure Concepts

Microsoft Certified: Azure Administrator AssociateENROLL NOW
Learn the Key Azure Concepts

Template Design

Find here the three methods to obtain the template:

Use Provided Template

The template can be readily deployed from the Azure Quickstart Template. To use them, follow these steps:

Step 1: Visit the Azure portal offering samples here.

Step 2: Choose the sample of your interest and select the ‘Browse on GitHub’ option.

Step 3: Select the ‘Visualize’ option to gain insight into the template.

Step 4: Choose to deploy the template by clicking the ‘Deploy’ option.

Create Template in Code Editor

Alternatively, you can create the template. Here are the steps to follow if you are interested in this option:

Step 1: Finalize the purpose of creating an Azure template and get insights into the latest schema on GitHub.

Step 2: Create a new file in a code editor like Visual Studio. Ensure it has a .json extension. To further facilitate the template creation process, install the VSCode ARM template extension for resource auto-completion, language support and resource snippets.

Step 3: Create the Azure ARM template based on the structure discussed in the previous section. Here is an Azure ARM template example for you to follow:

Basic Structure: 

{

"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",

  "contentVersion": "1.0.0.0",

  "resources": [],

  "outputs": {}

}

Resource: 

"resources": [

    {

      "type": "Microsoft.Network/virtualNetworks",

      "apiVersion": "2020-11-01",

      "name": "MyVNet",

      "location": "East US",

      "properties": {

        "addressSpace": {

          "addressPrefixes": [

            "10.0.0.0/16"

          ]

        },

        "subnets": [

          {

            "name": "MySubnet",

            "properties": {

              "addressPrefix": "10.0.0.0/24"

            }

          }

        ]

      }

    }

  ]

Step 4: Proceed to deploy the ARM template in Azure, as discussed in the next section.

Create Template in Azure Portal

If you have access to the Azure portal, then the process will go like this:

Step 1: Go to the Azure Portal and click the ‘Create a Resource’ button.

Step 2: In the next window, find and click on ‘Template Deployment (deploy using custom template).’

Step 3: Select the ‘Create’ option, and in the ‘Custom Deployment’ window, select the ‘Build your template in the editor’ option.

Step 4: You can also choose to ‘Load file’ to import the template.

Skyrocket Your Cloud Computing Career with Us!

Microsoft Certified: Azure Administrator AssociateENROLL NOW
Skyrocket Your Cloud Computing Career with Us!

Template Deployment Process

There are different ways to deploy ARM templates in Azure, like through PowerShell or Azure CLI. Find here how to deploy with PowerShell. The prerequisites are PowerShell 5.1 or later, Az PowerShell module version 6.0.0 or later and an Azure account with resource creation permissions. 

Now, go as follows:

Step 1: Sign in to your Azure account through PowerShell by running the Connect-AzAccount command.

Step 2: Name the Resource group and assign an Azure region with the New-AzResourceGroup command.

Step 3: Use the ARM template saved with .json format.

Step 4: Deploy the ARM template in Azure with the New-AzResourceGroupDeployment command, specifying the resource group, path to the template file and required parameters.

Here is an Azure ARM template example script for deployment:

# Define the resource group name, deployment name, and template file path

$resourceGroupName = "MyResourceGroup"  # Replace with your desired resource group name

$deploymentName = "MyVNETDeployment"    # Replace with your desired deployment name

$templateFile = "C:\Path\To\Your\vnet.json"  # Replace with the path to your ARM template file

# Log in to Azure (enter credentials when prompted)

Connect-AzAccount

# Create a new resource group (if it doesn't exist)

New-AzResourceGroup -Name $resourceGroupName -Location "East US"

# Deploy the ARM template to the resource group

New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -Name $deploymentName -TemplateFile $templateFile

There are two ARM deployment modes: incremental and complete. The deployment automatically operates in incremental mode. It can be changed to complete mode by specifying - - mode Complete.

  1. Incremental Mode: This mode is used when deploying and updating changed or new resources. This feature makes it suitable for regular updates involving modification of specific resources rather than working over the entire resource group.
  2. Complete Mode: Opposite to incremental mode, it includes complete deployment and updating all defined resources in the template. If not specified in the new template, it leads to a change of resources (deletion) of any previous resources.

To deploy using the complete mode in Azure PowerShell, modify the following sample:

New-AzResourceGroupDeployment -ResourceGroupName MyResourceGroup -TemplateFile .\azuredeploy.json -TemplateParameterFile .\azuredeploy.parameters.json -Mode Complete

Azure DevOps Solutions Expert Master's Program

Start Your Career in Azure Cloud and DevOps TodayApply Now
Azure DevOps Solutions Expert Master's Program

Share Templates

Created templates can be shared with other users in the organization through template specs. Template storage is allowed as a resource type. Further, the sharing is secure with an access control feature, allowing the freedom to view or modify as decided.

Conclusion

Azure Resource Manager (ARM) is a critical component of every business and essential to Microsoft’s cloud services. Widely used among MNCs and Fortune 500 companies, the expertise in the field offers many opportunities to succeed in the career.

Simplilearn offers the Microsoft Certified: Azure Administrator Associate AZ-104 certification in alignment with Microsoft Azure. The course includes a simulation test, live virtual classes, practice labs, projects with Azure labs, and much more. Visit the course page to learn more.

FAQs

1. Which is better, Terraform or ARM template?

The better option depends on one's needs. Both have certain strengths, such as Terraform's suitability for multi-cloud or on-premise environments. However, ARM templates are the best option if you only use Azure.

2. What are ARM templates in AWS?

JavaScript Object Notation (JSON) files are the Azure Resource Manager templates that state the project's configuration and infrastructure.

3. What are the disadvantages of ARM templates?

One of the disadvantages is the limitation of ARM templates to Azure cloud deployments.

4. Are ARM templates IaC?

ARM templates manage the Azure resources through Infrastructure as Code (IaC). They use declarative JSON code to define and deploy the cloud infrastructure.

5. Which syntax is used in ARM templates?

The basic syntax of Azure ARM templates is JavaScript Object Notation (JSON).

About the Author

Sachin SatishSachin Satish

Sachin Satish is a Senior Product Manager at Simplilearn, with over 8 years of experience in product management and design. He holds an MBA degree and is dedicated to leveraging technology to drive growth and enhance user experiences.

View More
  • Disclaimer
  • PMP, PMI, PMBOK, CAPM, PgMP, PfMP, ACP, PBA, RMP, SP, OPM3 and the PMI ATP seal are the registered marks of the Project Management Institute, Inc.