Skill 3.1: Automate deployment of resources
The ability to provision virtual machines on demand using the Azure portal is incredibly pow- erful. The true power of the cloud, however, is the ability to automatically deploy one or more resources defined in code, such as a script or a template. Use cases such as defining an appli- cation configuration and automatically deploying it on demand help teams to be more agile by providing developer, test, or production environments in a fast and repeatable fashion.
Because the configuration is stored as code, changes to infrastructure can also be tracked in a version control system. In this skill, you will learn some of the core capabilities for automating workload deployments in Azure.
Interpret an Azure Resource Manager template
Azure Resource Manager (ARM) templates are authored using JavaScript Object Nota- tion (JSON) and provide the ability to define the configuration of resources, such as virtual machines, storage accounts, and so on, in a declarative manner. Templates go beyond just
providing the ability to create the resources; you can also customize and create dependencies between some resources, such as virtual machines. This makes it possible to create templates that have capabilities for orchestrated deployments of completely functional solutions.
The Azure team maintains a list of ARM templates with examples for most resources. This list is located at https://azure.microsoft.com/resources/templates/ and is backed by a source code repository in GitHub. If you want to go directly to the source to file a bug, you can access it at https://github.com/Azure/azure-quickstart-templates.
The basic structure of a resource manager template has most of the following elements:
{
“$schema”: “https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.
“contentVersion”: “1.0.0.0”, “parameters”: { },
“variables”: { },
“functions”: [ ],
“resources”: [ ],
“outputs”: { }
}
- $schema The JSON schema file is the reference to the standard structure defined for an ARM template, which can help you determine when something is wrong with your template in comparison to the schema file syntax. The JSON schema is used by features, such as code completion or IntelliSense, so you can make changes in the templates easily.
For resource group targeted deployments, use
https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#
- contentVersion This provides source control to track the changes made in your tem- plate. You can provide any value for this element. When deploying resources using the template, this value can be used to make sure that the right template is being used.
- parameters Using parameters, you can define the values that are passed at run- time without changing the exact template file. The parameters can be changed by the azuredeploy.parameters.json file or in the PowerShell script that is used to deploy your template. The parameters are key elements when dealing with nested templates to pass the values from parent template to the child templates.
- variables This defines values that are used in your template to simplify template lan- guage. Mostly, variables are hard-coded values, but they also can be created dynamically using parameters or standard template functions.
- functions Users can create functions that can be used within the template. The com- plex expressions that are being used multiple times in the template can be defined as a function once. You need to create your own namespace and create member functions as needed. You cannot access variables or any other user-defined functions within your function.
- resources This contains resources that are deployed or updated in a resource group. You can define the condition to control the provisioning of each resource. Also, the dependsOn value determines which resources must be deployed first before a specific resource.
- outputs Here, you can define the type of values that are returned after deployment.
This section is used to keep track of resources that are being deployed or updated.