ARM templates, or Azure Resource Manager templates, are widely used in the IT world to define the infrastructure and configuration for your project. They help in deploying Azure resources in a more time-effective, reliable, and consistent manner. One of the most crucial skills Azure Administrators aiming to pass the AZ-104 exam need to acquire is the ability to modify an ARM template.
Understanding ARM Templates
An ARM template is a file written in JavaScript Object Notation (JSON). Its fundamental structure consists of six top-level elements: parameters, variables, functions, resources, outputs, and expressions.
Modifying an ARM Template
Here, we’ll specifically focus on modifying an existing Arm Template. Following are the steps you need to take:
- Read & Understand the Existing Template: You cannot modify an ARM template without knowing what the original one contains. It consists of parameters, variables, resources, and outputs. Get an understanding of each to comprehend how the current system works.
- Identify the Required Changes: The next step is to identify what you exactly need to modify in the Template. These changes can be:
- Adding new resources
- Deleting existing resources
- Modifying properties of existing resources
- Implement the Changes: Once you’ve identified the changes, start implementing them one by one. Either directly modify the template or make use of Visual Studio Code with Azure Resource Manager Tools extension installed. VS Code highlights potential issues as you type and also provides intellisense suggestions, which makes the modification process easier.
Example
Example project scenario: Modify an existing ARM template to enable Soft Delete policy on Storage Accounts.
The original template for creating a storage account might look something like this:
{
“$schema”: “https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#”,
“contentVersion”: “1.0.0.0”,
“parameters”: {
“storageName”: {
“type”: “string”
}
},
“resources”: [
{
“type”: “Microsoft.Storage/storageAccounts”,
“apiVersion”: “2019-06-01”,
“name”: “[parameters(‘storageName’)]”,
“location”: “[resourceGroup().location]”,
“sku”: {
“name”: “Standard_GRS”
},
“kind”: “StorageV2”
}
]
}
To add the Soft Delete policy on this Storage Account, modify the template to look like this:
{
“$schema”: “https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#”,
“contentVersion”: “1.0.0.0”,
“parameters”: {
“storageName”: {
“type”: “string”
}
},
“resources”: [
{
“type”: “Microsoft.Storage/storageAccounts”,
“apiVersion”: “2019-06-01”,
“name”: “[parameters(‘storageName’)]”,
“location”: “[resourceGroup().location]”,
“sku”: {
“name”: “Standard_GRS”
},
“kind”: “StorageV2”,
“properties”: {
“deleteRetentionPolicy”: {
“enabled”: true,
“days”: 7
}
}
}
]
}
In the modified template, we added a properties section in the resource block with deleteRetentionPolicy enabled and set to last 7 days.
Thus, Azure Administrators aiming for the AZ-104 exam must have the ability to implement such modifications.
Conclusion
Modifying an ARM template could seem complicated initially but if you follow the steps of understanding, identifying, and implementing, it becomes relatively easy. Moreover, tools like Visual Studio Code greatly aid in making these modifications efficiently. Aspiring Azure Administrators should invest time in learning this skill to crack the AZ-104 exam.
Practice Test
True/False: It is necessary to define the “parameters” section in an ARM template.
- True
- False
Answer: False
Explanation: The ‘parameters’ section isn’t a mandatory requirement for an ARM template. It is used to customize the deployment by receiving input values during the deployment.
Single Select: Which section of an ARM template defines the deployment sequence?
- a. parameters
- b. resources
- c. variables
- d. outputs
Answer: b. resources
Explanation: The ‘resources’ section of an ARM template defines the deployment sequence and dependencies between resources.
Multiple Select: Which of the following are sections within an ARM template?
- a. parameters
- b. resources
- c. dependencies
- d. variables
Answer: a. parameters, b. resources, d. variables
Explanation: The ARM template consists of a number of sections including parameters, variables, and resources. Dependencies are not a section but are defined within the resources section.
True/False: Defining dependencies in an ARM template can ensure resources are deployed in the correct order.
- True
- False
Answer: True
Explanation: Defining dependencies within the ‘resources’ section can control the order of deployment and ensure resources that depend on others are not deployed before their dependencies.
Single Select: In ARM templates, where do you specify the values that are used when you deploy the resources?
- a. parameters
- b. values
- c. mappings
- d. variables
Answer: a. parameters
Explanation: The ‘parameters’ section of an ARM template is used for customizing deployments and specifying input values during the deployment.
Multiple Select: What are use cases for ARM templates?
- a. Defining the deployment order
- b. Keep infrastructure and configuration code together
- c. As a substitution for Azure CLI or PowerShell scripts
- d. As an Azure resource group
Answer: a. Defining the deployment order, b. Keep infrastructure and configuration code together, c. As a substitution for Azure CLI or PowerShell scripts
Explanation: ARM templates are mainly used for defining the deployment order, keeping infrastructure and configuration code together, and as a substitution for Azure CLI or PowerShell scripts. They are not used as an Azure resource group.
True/False: You are allowed to use expressions in the ‘outputs’ section of an ARM template.
- True
- False
Answer: True
Explanation: In the outputs section of an ARM template, you can use expressions to manipulate data received as a result of your deployment.
Single Select: What is the minimum requirement to deploy an ARM template?
- a. An Azure account
- b. A JSON file
- c. A PowerShell script
- d. An SSH key
Answer: a. An Azure account
Explanation: You can deploy ARM templates via the Azure portal, Azure CLI, or PowerShell, but regardless of the method, an Azure account is the minimum requirement.
Multiple Select: Which tools can you use to deploy an ARM template?
- a. Azure CLI
- b. Azure PowerShell
- c. Azure portal
- d. Azure DevOps
Answer: a. Azure CLI, b. Azure PowerShell, c. Azure portal, d. Azure DevOps
Explanation: You can deploy ARM templates using Azure CLI, Azure PowerShell, the Azure portal, or as part of an Azure DevOps Pipeline.
True/False: It is possible to define a resource in one ARM template that depends on a resource in another ARM template.
- True
- False
Answer: False
Explanation: When using ARM templates each template defines its own set of resources. There isn’t a mechanism that can make a resource from one ARM template dependent on a resource from another template. They’re processed independently.
Interview Questions
What is an ARM Template in Azure?
In Azure, the Azure Resource Manager (ARM) template is a file written in JSON format. It defines the services and properties for your Azure solution. With an ARM template, you can deploy and configure interdependent services collectively which ensures repeatable, consistent deployments.
How do you modify an ARM template?
An ARM template can be modified using a text editor. The JSON file can have multiple lines, each referring to the resources you want to implement or manage. You should examine the JSON structure carefully before modifying it to prevent any errors in deployment.
How do you deploy an ARM template?
You can deploy an ARM template via the Azure portal, Azure PowerShell, Azure CLI, or directly from the Visual Studio Code extension.
Where would you specify parameters in an ARM template?
Parameters are specified in the “parameters” section of an ARM template, which is defined in the JSON file. Parameters allow for input values that control the behavior of the deployment.
What is the significance of the “Resources” object in an ARM template?
The “Resources” object in an ARM template is where you describe the resources that you want to deploy to the resource group. Each resource is a separate object in the “Resources” array.
Can you add comments in ARM templates?
Yes, you can add comments in ARM templates. However, as JSON does not directly support comments, Azure uses a workaround by treating comments as metadata within the “_comment” tag.
What does the “outputs” block in an ARM template do?
The “outputs” block in an ARM template is used to return values from the deployed resources. These outputs can then be used to display information about the deployed resources or passed as inputs to other templates.
What is the purpose of variables in an ARM template?
Variables in an ARM template are used to simplify template language expressions. They are used to declare values that can be reused in a template.
Can I use conditions in an ARM template?
Yes, you can use conditions in an ARM template to control whether the resource is deployed or how the properties are assigned a value.
How can you manage dependencies in an ARM template?
You can manage dependencies in an ARM template by using the “dependsOn” element. It specifies that a resource depends on one or more resources.
What is a quickstart template in ARM?
Quickstart templates in ARM are pre-written templates in GitHub that demonstrate a quick way to get started with common configurations.
Can I validate my ARM template before deploying?
Yes, you can validate your ARM template before deploying using Azure PowerShell cmdlet, Test-AzResourceGroupDeployment, or the Azure CLI command, az group deployment validate.
Can I deploy an ARM template committing to a GitHub repository?
Yes, if you commit ARM templates to GitHub repositories, you can set up GitHub Actions to automatically deploy your ARM template when the master branch is updated.
How can you handle complex deployments using ARM templates?
For complex deployments, you can use linked templates. A linked template is an ARM template that is referenced by another ARM template during a deployment.
How does Azure handle conflicts when deploying ARM templates?
In the event of a conflict during ARM template deployment, Azure uses an optimistic concurrency control model. If the resource has been modified by someone else since you last read it, your update fails.