Articles → MICROSOFT AZURE → Apply locks to a resource group using the ARM template in Azure

Apply locks to a resource group using the ARM template in Azure






Creation of the resource group




Picture showing the resource group on which lock will be applied using the ARM template

Click to Enlarge


Deploy using ARM




Picture showing the Export template menu in Azure portal

Click to Enlarge



Picture showing the Deploy button for deploying the ARM template

Click to Enlarge



Picture showing the Edit template for editing the ARM template

Click to Enlarge



{
  "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {},
  "variables": {},
  "resources": [
    {
      "type": "Microsoft.Resources/resourceGroups",
      "apiVersion": "2021-04-01",
      "name": "RG1111",
      "location": "eastus",
      "properties": {}
    },
    {
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2021-04-01",
      "name": "lockDeployment",
      "resourceGroup": "RG1111",
      "dependsOn": [
        "RG1111"
      ],
      "properties": {
        "mode": "Incremental",
        "template": {
          "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
          "contentVersion": "1.0.0.0",
          "parameters": {},
          "variables": {},
          "resources": [
            {
              "type": "Microsoft.Authorization/locks",
              "apiVersion": "2016-09-01",
              "name": "rgLock",
              "properties": {
                "level": "CanNotDelete",
                "notes": "Resource group and its resources should not be deleted."
              }
            }
          ],
          "outputs": {}
        }
      }
    }
  ],
  "outputs": {}
}


Picture showing the template updated with the updated ARM script

Click to Enlarge



Picture showing the Review + Create button for deploying the updated ARM template

Click to Enlarge



Picture showing the message the confirms that validation is passed

Click to Enlarge



Picture showing the lock created on the resource group using the ARM template

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Sunday, November 14, 2021

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250