Azure Resource Manager Templates
- These are JSON files that define the infrastructure and configuration of your application.
- These templates can be reused to create the same application cofiguration in different
- resource groups
- subscriptions
- Consider the scenario where you need to deploy the following architecture into various environments (DEV, QA, STAGING, PRODUCTION)
- To solve this we need some kind of automation,
- One approach will be to write a script using Azure CLI / Azure Powershell. The problem with this approach changing the script for any updates in architectures and changing values for resources like vm size, zone etc will be difficult to handle
- Second approach is to create a template that defines the above architecture in json format and execute it on various environments.
- ARM Templates provide us the following advantages
- declarative syntax
- Repeatable results
- Orchestration
- Modular files
- Preview changes
- Tracked deployments
- Exercise:
- Create one linux vm in a new resource group
- After linux vm is created, add one windows vm to the same resource group
- Now navigate to the resource group section and select the created resource group
- Azure is creating a template when we try to create resources.
- In this section we will learn how to create an arm template,
- To do this lets setup our developer environment
- Ensure Azure CLI or Azure Powershell is installed on your machine Refer Here
- Ensure Visual studio code is installed
How are resources created in Azure
- In your subscription, you will have resource providers
- Resource Provider in azure is capable of creating resources which it provides or offers
- When we try to create any resource in Azure (from portal/cli/arm template)
- It will check if the resource provider is registered or not
- If the resource provider is not registered then it will throw error messages
- If the resource provide is register then it will validate the values passed and if they are ok resources will be created.
ARM Template file
- ARM Template has 5 sections
- Parameters
- Variables
- User-defined functions
- Resources
- Outputs
- The template format Refer Here
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "",
"apiProfile": "",
"parameters": { },
"variables": { },
"functions": [ ],
"resources": [ ],
"outputs": { }
}
- So the minimal arm template will be
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "",
"resources": [ ]
}
- Now lets try to understand how to fill these sections
- For filling Schema section: We need to understand what is the deployment level
- Resource Group: "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#"
- Subscription: "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#"
- Tenant Level: "https://schema.management.azure.com/schemas/2019-08-01/tenantDeploymentTemplate.json#"
- Management Group: "https://schema.management.azure.com/schemas/2019-08-01/managementGroupDeploymentTemplate.json#"
- Content version: version of your template
- resources: This specifies what you want to create. Now lets try to create a storage account
- manual steps:
- Create a resource group
- Create a storage account
- manual steps:
- Lets try to write a arm template to do the same thing, lets start by filling $schema, contentVersion. Refer Here for the changes
- Now we need to add the resource storage account
- Navigate to the page Refer Here
- Refer Here to this changeset to fill to storage account information
- Further reading
- Next Steps:
- Lets try to execute the template and see the results
- Lets explore more options
