Microsoft Azure is an expansive set of cloud services that aid businesses to meet their organizational challenges. Among the numerous services provided by Azure, one of the pivotal tasks for Azure Administrators is to deploy templates. A vital part of the AZ-104 Microsoft Azure Administrator exam involves understanding the methods and applications of template deployments.
What is an Azure Resource Manager Template?
Azure Resource Manager (ARM) template is a JavaScript Object Notation (JSON) file that defines the infrastructure and configuration for your Azure solution. It allows Azure administrators to deploy and manage resources in Azure in consistent and repeatable manners. Developers can create an ARM template defining the resources to be deployed and their configurations. The ARM service interprets the template and takes care of deploying and configuring those resources in the appropriate order.
Why Use Azure Resource Manager Templates?
Azure Resource Manager Templates offer the following advantages over using the Azure Portal for managing resources:
- Consistency: Developing templates for Azure resource deployment provides consistent, repeatable results that are less prone to human error.
- Declarative Syntax: ARM templates use a declarative syntax to define resource deployment, which means you define what you want and let Azure Resource Manager worry about how to achieve it.
- Modularity: Templates can be linked together allowing the construction of reusable module templates reducing code duplication.
- Infrastructure as Code: ARM templates can be stored in source control systems enabling standard source control operations like branching and versioning.
How to Deploy an Azure Resource Manager Template?
Azure provides multiple ways to deploy ARM templates, such as Azure Portal, Azure PowerShell, Azure CLI, and REST API. Here, we illustrate how to deploy an ARM template using Azure Portal:
- Sign in to the Azure portal.
- On the left menu, select “Create a resource”>”Custom”> “Build your own template in the editor”.
- Load your template into the editor either by copy-pasting it or uploading the JSON file. Then, click “Save”.
- Fill the parameters, choose a subscription, resource group, and location then click “Review + create”.
- After Azure validates your template, click “Create”.
Example of ARM Template Deployment
Below is an example of an ARM template JSON file that deploys a storage account:
{
“$schema”: “https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#”,
“contentVersion”: “1.0.0.0”,
“resources”: [
{
“type”: “Microsoft.Storage/storageAccounts”,
“apiVersion”: “2019-06-01”,
“name”: “[parameters(‘storageAccountName’)]”,
“location”: “[parameters(‘location’)]”,
“kind”: “StorageV2”,
“sku”: {
“name”: “Standard_LRS”
}
}
],
“parameters”: {
“storageAccountName”: {
“type”: “string”
},
“location”: {
“type”: “string”
}
}
}
The template might look more complicated than just using the Azure Portal to create a storage account, but it provides the benefit of reusability and consistency across multiple deployments.
For Azure administrators planning to take the AZ-104 exam, understanding template deployments is crucial. It not only boosts their efficiency in managing Azure resources but also offers a consistent and error-free approach. Employing templates for Azure resource deployment serves as a valuable skill for any Azure Administrator.
Practice Test
True/False: In Microsoft Azure, the deployment of templates involves three steps: authoring the template, deploying the template, and maintaining the template.
- True
- False
Answer: True.
Explanation: Deploying a template in Microsoft Azure involves authoring the template (defining the infrastructure and configuring its settings), deploying the template (running the template to create or update an Azure resource), and maintaining the template (updating and modifying the template).
Single Select: Which of the following template languages can be used in Azure?
- a) Azure Resource Manager template
- b) JavaScript
- c) Python
- d) Ruby
Answer: a. Azure Resource Manager template
Explanation: Azure Resource Manager template is a declarative programming language used in Azure for defining and deploying Azure resources.
Multiple Select: What are the different ways to deploy a template in Azure?
- a) Azure portal
- b) Azure CLI
- c) PowerShell
- d) REST API
Answer: a. Azure portal, b. Azure CLI, c. PowerShell, d. REST API
Explanation: You can deploy templates in Azure by using the Azure portal, Azure CLI, PowerShell or the REST API. Each of these methods allows for a different way of interacting with Azure.
True/False: You can’t deploy multiple resources simultaneously using a single Azure Resource Manager template.
- True
- False
Answer: False.
Explanation: An Azure Resource Manager template can define all the resources that a solution needs, enabling you to deploy, update, and delete all the resources for your solution in a single, coordinated operation.
Single Select: What JSON file structure does Azure Resource Manager template use?
- a) { “resources”: [] }
- b) { “source”: [] }
- c) { “template”: [] }
- d) { “manager”: [] }
Answer: a. { “resources”: [] }
Explanation: Azure Resource Manager uses JSON to define a template, and the “resources” property is an array that contains the resources you want to deploy or update.
True/False: You can validate your Azure Resource Manager templates before deploying them.
- True
- False
Answer: True.
Explanation: Azure Resource Manager allows you to validate your templates before deployment to check for errors and ensure they will deploy successfully.
Single Select: In what scenario would you use an incremental deployment mode?
- a) When you want to delete resources not specified in the template.
- b) When you only want to add or update resources.
- c) When you want to ensure a template doesn’t exist.
- d) When you want to clone a resource.
Answer: b. When you only want to add or update resources.
Explanation: The incremental deployment mode in Azure Resource Manager templates is used when you only want to add or update resources, but not delete ones that aren’t specified in the template.
Multiple Select: Which deployment tools support the complete deployment lifecycle of Azure Resource Manager templates?
- a) Azure portal
- b) Azure CLI
- c) PowerShell
- d) Azure DevOps
Answer: a. Azure portal, b. Azure CLI, c. PowerShell, d. Azure DevOps
Explanation: Azure portal, Azure CLI, PowerShell, and Azure DevOps support the complete deployment lifecycle of Azure Resource Manager templates including authoring, deploying, and maintaining them.
True/False: The unique name you assign to resources in the Azure Resource Manager template needs to be hard coded.
- True
- False
Answer: False.
Explanation: Names for resources do not need to be hard coded. You can use functions to construct names and establish relationships between nested resources.
Single Select: The ‘parameters’ section of an Azure Resource Manager template is used to?
- a) Specify the resources to deploy.
- b) Input values that are used when deploying the template.
- c) Connect resources with dependencies.
- d) Report on the status of the deployment.
Answer: b. Input values that are used when deploying the template.
Explanation: The ‘parameters’ section of an Azure Resource Manager template is used to input values that are used when deploying the template. This allows for template flexibility and can be used with different values for different deployments.
Interview Questions
What is a Template in Azure?
A template in Azure is a JSON file that defines the infrastructure and configuration for your project. It enables you to repeatedly deploy your application during every stage of the application lifecycle.
What is the ARM templates in Azure?
ARM templates are JavaScript Object Notation (JSON) files that define the infrastructure and configuration for your project. They enable you to use declarative syntax to state what you intend to deploy in Azure.
What command can be used to deploy a template in Azure using Azure CLI?
The command “az deployment group create” can be used to deploy a template in Azure using the Azure CLI.
What are the two main sections of an Azure Resource Manager Template?
The two main sections of an Azure Resource Manager Template are the parameters and the resources. The parameters allow the template to be customized, and the resources define what resources to deploy and configure.
How can a template be tested in Azure before deployment?
A template can be tested in Azure before deployment using the “What-if operation”. This enables you to preview and validate changes a template will make before committing those changes.
Can you change the parameters in a previously deployed template in Azure?
Yes, you can change the parameters in a previously deployed template by re-deploying the template with the updated parameters.
Is it possible to deploy a template directly from the Azure Portal?
Yes, it’s possible to deploy a template directly from the Azure Portal. This can be done on the template deployment blade with the “Deploy a custom template” button.
What is a deployment mode in Azure Resource Manager Templates?
A deployment mode determines how Resource Manager handles existing resources during deployment. There are two types: Incremental and Complete. Incremental mode leaves unchanged resources that exist in the resource group but are not specified in the template. Complete mode deletes resources that exist in the resource group but are not specified in the template.
How do you specify default values for parameters in Azure Resource Manager Templates?
You can specify default values for parameters by including a “defaultValue” property in the parameter definition in the Azure Resource Manager Template.
Can you link to another template from within an Azure Resource Manager Template?
Yes, you can link to another template from within an Azure Resource Manager Template using the “linked templates” function.
Can you use loops in an Azure Resource Manager Template?
Yes, you can use the “copy” function to make loops in Azure Resource Manager Templates to create multiple instances of resources.
How do you specify the order of deployment of resources within a template?
You can control the order of deployment of resources within a template by using the “dependsOn” property.
Can you call REST APIs from an Azure Resource Manager Template?
Yes, you can call REST APIs from an Azure Resource Manager Template using the ‘DeploymentScript’ resource.
What function can be used to retrieve the properties of existing resources in a template in Azure?
The `reference` function can be used to retrieve the properties of existing resources in a template in Azure.
Can you use conditions in an Azure Resource Manager Template?
Yes, you can use the “condition” element to conditionally deploy resources in an Azure Resource Manager Template. This is helpful when you need to limit what resources are created in different environments.