What is ARM template?
To implement infrastructure as code for your Azure solutions, you can use Azure Resource Manager templates (ARM templates). The template is a JavaScript Object Notation (JSON) file that defines the infrastructure and configuration for your project. The template uses declarative syntax, which lets you state what you intend to deploy without having to write the sequence of programming commands to create it. In the template, you specify the resources to deploy and the properties for those resources.
How to deploy an ARM template using Azure CLI?
Step 1: Create a new resource group to deploy the ARM template.
1 2 3 4 |
## Create a new Azure resource group az group create \ --name MyResourceGroup \ --location centralindia |
Step 2: Create an ARM template definition and parameters to pass to the ARM template:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
cat << 'EOF' > mydeploymentTemplate.json { "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "networkSecurityGroupName": { "type": "string", "metadata": { "description": "This is the name of the network security group" } }, "location": { "type": "string", "metadata": { "description": "Location where the network security group resource will be created." } } }, "resources": [ { "apiVersion": "2019-02-01", "type": "Microsoft.Network/networkSecurityGroups", "name": "[parameters('networkSecurityGroupName')]", "location": "[parameters('location')]", "tags": { "Name": "DemoNSG" } } ] } EOF cat << 'EOF' > mydeploymentParameters.json { "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#", "contentVersion": "1.0.0.0", "parameters": { "networkSecurityGroupName": { "value": "MyNSG" }, "location": { "value": "centralindia" } } } EOF |
Step 3: Validate the deployment file and parameters
1 2 3 4 5 6 7 8 9 10 11 12 |
## Validate the deployment files az deployment group validate \ --resource-group MyResourceGroup \ --template-file mydeploymentTemplate.json \ --parameters @mydeploymentParameters.json ## Review the deployment without deploying az deployment group what-if \ --name MyDeployment \ --resource-group MyResourceGroup \ --template-file mydeploymentTemplate.json \ --parameters @mydeploymentParameters.json |
Step 4: Create a new deployment.
1 2 3 4 5 6 7 8 9 10 11 12 |
## Create a new deployment az deployment group create \ --name MyDeployment \ --resource-group MyResourceGroup \ --template-file mydeploymentTemplate.json \ --parameters @mydeploymentParameters.json ## Optionally you can also cancel a running deployment ## Cancel a running deployement az deployment group cancel \ --name MyDeployment \ --resource-group MyResourceGroup |
Step 5: Get details on the deployment using Azure CLI
1 2 3 4 5 6 7 8 9 10 11 12 13 |
## List all deployments by resource group az deployment group list \ --resource-group MyResourceGroup ## Get details on a deployment az deployment group show \ --name MyDeployment \ --resource-group MyResourceGroup ## Get the template used for the deployment az deployment group export \ --name MyDeployment \ --resource-group MyResourceGroup |
Step 6: Clean up.
1 2 3 4 5 6 7 8 9 10 11 12 |
## Delete the deployment az deployment group delete \ --name MyDeployment \ --resource-group MyResourceGroup \ --no-wait ## Note: Does not delete the actual resouces ## Delete the resource group az group delete \ --name MyResourceGroup \ --yes |
thank you very clear and concise article.