Devendra Pal Singh
Devendra Pal Singh

Reputation: 43

Resource Group Lock using ARM Template

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.

Upvotes: 2

Views: 3147

Answers (2)

Sa Yang
Sa Yang

Reputation: 9401

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.

Upvotes: 6

4c74356b41
4c74356b41

Reputation: 72151

{
  "$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

Upvotes: 3

Related Questions