Table of Contents
An ARM template is a JSON file containing five main sections:
$schema
: Points to the schema defining the version of the template.contentVersion
: Specifies the version of the template (provided by the author).parameters
: Define values that can be inputted externally at deployment time.variables
: Define values used within the template to simplify complex expressions.resources
: Specifies the resources to be deployed or updated.outputs
: Contains values that are returned after deployment.Before modifying a template, you need to get the current ARM template for an existing resource. You can do this through the Azure Portal or using Azure CLI commands. Here is how you can retrieve a template via the Azure CLI:
az resource group export-template –resource-group <ResourceGroupName> –name <ResourceName> > template.json
After obtaining the template, open it in a code editor such as Visual Studio Code. Locate the section of the template where you want to make changes, for example, the parameters
or resources
section.
Parameters can be edited to introduce new variables or edit existing ones. For example, if you wish to change the size of a virtual machine:
“parameters”: {
“vmSize”: {
“type”: “string”,
“defaultValue”: “Standard_DS2_v2”,
“allowedValues”: [
“Standard_DS1_v2”,
“Standard_DS2_v2”,
“Standard_DS3_v2”
],
“metadata”: {
“description”: “The size of the VM”
}
}
}
You can change the defaultValue
or allowedValues
here to modify the VM size options.
This is where you define the properties for each resource. For instance, if you’re modifying a VM’s network interface, you might do the following:
“resources”: [
{
“type”: “Microsoft.Network/networkInterfaces”,
“apiVersion”: “2020-11-01”,
“name”: “[variables(‘networkInterfaceName’)]”,
“location”: “[parameters(‘location’)]”,
“properties”: {
“ipConfigurations”: [
{
“name”: “ipconfig1”,
“properties”: {
“subnet”: {
“id”: “[variables(‘subnetRef’)]”
},
“privateIPAllocationMethod”: “Dynamic”
}
}
]
}
}
]
You could add or modify properties like privateIPAllocationMethod
or the subnet association here.
Make sure that resources that rely on each other have the right dependencies updated. Use the dependsOn
property to explicitly define dependencies.
Use Azure CLI or Azure PowerShell to validate the ARM template before deployment.
az deployment group validate –resource-group <ResourceGroupName> –template-file <PathToTemplateFile>
After validation, deploy the template with the updated configurations.
az deployment group create –resource-group <ResourceGroupName> –template-file <PathToTemplateFile>
Modifying an ARM template is integral to tailoring Azure resource deployments. For the AZ-104 Microsoft Azure Administrator exam, it’s crucial to become familiar with the ARM template structure, understand how to edit various components, implement best practices, and validate changes. Through practice and experience, modifying ARM templates becomes a fluent part of managing Azure resources.
Answer: False
Explanation: Parameters in ARM templates are optional. They allow a user to input values during deployment, but they are not strictly required.
Answer: False
Explanation: It is not necessary to always increment the API version when modifying an ARM template. API version should be updated if you need functionality from a newer API version or if the old version is deprecated.
Answer: Parameters
Explanation: The parameters section of an ARM template is used to define parameters along with their metadata like default values, allowed values, and data types.
Answer: True
Explanation: Resource dependencies must be manually defined using the “dependsOn” property in ARM templates to ensure resources are created in the correct order.
Answer: All options are correct.
Explanation: In ARM templates, the location of a resource can be hard-coded, passed as a parameter, defined by a variable, or derived from the resource group’s location, providing flexibility in the deployment.
Answer: True
Explanation: The “outputs” section of an ARM template is used to return information from deployed resources, such as connection strings, keys, and URIs.
Answer: az deployment validate
Explanation: The “az deployment validate” command is used to validate an ARM template’s syntax and semantics before actual deployment occurs.
Answer: True
Explanation: ARM template functions provide the ability to create complex expressions including conditionals and loops within the template.
Answer: True
Explanation: A copy loop can be defined in an ARM template to create multiple instances of a resource, like virtual machines.
Answer: Specifies the version of the template content for internal use
Explanation: The “contentVersion” field in an ARM template does not have any effect on the deployment but is for internal documentation or version control purposes.
Answer: True
Explanation: ARM templates support linked templates, which can be stored in Azure Blob storage or in an external location. They can be referenced by the main template for modular deployments.
Answer: .parameters.json file
Explanation: A .parameters.json file often accompanies an ARM template to provide different parameter values that may change between deployments, making it reusable under different deployment scenarios.
If this material is helpful, please leave a comment and support us to continue.