Tutorial / Cram Notes
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.
Steps to Modify an ARM Template
1. Retrieve the Existing Template
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
2. Edit the Template
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.
3. Modify Parameters
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.
4. Modify Resources
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.
5. Update Dependencies
Make sure that resources that rely on each other have the right dependencies updated. Use the dependsOn
property to explicitly define dependencies.
6. Validate the Template
Use Azure CLI or Azure PowerShell to validate the ARM template before deployment.
az deployment group validate –resource-group <ResourceGroupName> –template-file <PathToTemplateFile>
7. Deploy the Template
After validation, deploy the template with the updated configurations.
az deployment group create –resource-group <ResourceGroupName> –template-file <PathToTemplateFile>
Best Practices
- Parameterize as much as possible: This allows for reusability and flexibility of templates.
- Use meaningful names: Keep resource and parameter names descriptive and consistent.
- Organize resources logically: Group related resources for clarity.
- Test your changes iteratively: After each modification, test the template to catch any errors quickly.
- Store templates in version control: Keeping a history of template changes helps track modifications and revert if necessary.
Conclusion
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.
Practice Test with Explanation
True or False: Parameters in ARM templates are required to deploy an Azure Resource Manager template?
- True
- False
Answer: False
Explanation: Parameters in ARM templates are optional. They allow a user to input values during deployment, but they are not strictly required.
When modifying an ARM template, you must always increment the API version for the resources defined in the template.
- True
- False
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.
Which section of an ARM template specifies default values, allowed values, and value types for parameters?
- resources
- variables
- outputs
- parameters
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.
True or False: Resource dependencies in ARM templates must be manually defined by the user.
- True
- False
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.
Which of the following are valid ways to define a resource location in an ARM template? (Choose all that apply)
- Hard-coded in the resource definition
- Using a parameter value
- Using a variable value
- Derived from the resource group’s location
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.
True or False: The “outputs” section in an ARM template is used to return values like connection strings, keys, and URIs after deployment.
- True
- False
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.
When modifying an existing ARM template, which command should you use to validate the changes without actually deploying resources?
- az deployment create
- az deployment validate
- az group create
- az resource validate
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.
True or False: ARM template functions can be used to create complex expressions like conditionals or loops within the template.
- True
- False
Answer: True
Explanation: ARM template functions provide the ability to create complex expressions including conditionals and loops within the template.
True or False: You can modify an ARM template to create multiple instances of a resource type, such as virtual machines, by defining a copy loop.
- True
- False
Answer: True
Explanation: A copy loop can be defined in an ARM template to create multiple instances of a resource, like virtual machines.
What is the purpose of the “contentVersion” field in an ARM template?
- Indicates the version of the ARM template schema
- Forces a redeployment of resources
- Specifies the version of the template content for internal use
- Determines the API version used for resources
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.
True or False: ARM templates can be stored in an Azure Blob storage and linked to a main template for modular deployments.
- True
- False
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.
Which of the following files typically accompanies an ARM template for defining parameters that may change between deployments?
- .json file
- .parameters.json file
- .config file
- .env file
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.
I recently started working with ARM templates. What are some common modifications you might need to do?
Can someone explain how to add a new resource to an existing ARM template?
Is it possible to parameterize an existing ARM template without changing the core logic?
Appreciate the blog post!
What’s the best way to manage secrets within an ARM template?
When modifying an existing ARM template, how do you ensure you don’t impact the currently running resources?
Which tools do you use to test the ARM templates?
I wish this blog provided more examples.