2

hi i am tried to lock a resource group in azure using ARM template but i am not able do so please help me if anyone already familiar.

dreftymac
  • 31,404
  • 26
  • 119
  • 182

2 Answers2

6

We can use template to lock resource group directly without creating storage account.

The next example applies a read-only lock to the resource group:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {},
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Authorization/locks",
            "apiVersion": "2015-01-01",
            "name": "MyGroupLock",
            "properties":
            {
                "level": "ReadOnly",
                "notes": "my notes"
            }
        }
    ],
    "outputs": {}
}

See more details about how to lock resource and resource group with template in this article.

Wayne Yang
  • 9,016
  • 2
  • 20
  • 40
3
{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "lockedResource": {
      "type": "string"
    }
  },
  "resources": [
    {
      "name": "[concat(parameters('lockedResource'), '/Microsoft.Authorization/myLock')]",
      "type": "Microsoft.Storage/storageAccounts/providers/locks",
      "apiVersion": "2015-01-01",
      "properties": {
        "level": "CannotDelete"
      }
    }
  ]
}

https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-group-lock-resources#template

4c74356b41
  • 69,186
  • 6
  • 100
  • 141