Gallery › Azure Purview › Azure Community Policy
Deploy Purview account CanNotDelete lock
Converted Policy AuditIfNotExists DeployIfNotExists Disabled Mode All Version 1.0.0
Deploys CanNotDelete lock on Purview account if not exists.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONazurepolicy.json · 86 lines
{
"name": "7adb4ad7-b400-441f-afdc-aa5d3812f632",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Deploy Purview account CanNotDelete lock",
"description": "Deploys CanNotDelete lock on Purview account if not exists.",
"metadata": {
"version": "1.0.0",
"category": "Azure Purview"
},
"mode": "All",
"parameters": {
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "DeployIfNotExists, AuditIfNotExists or Disabled the execution of the Policy"
},
"allowedValues": [
"DeployIfNotExists",
"AuditIfNotExists",
"Disabled"
],
"defaultValue": "DeployIfNotExists"
}
},
"policyRule": {
"if": {
"field": "type",
"equals": "Microsoft.Purview/accounts"
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.Authorization/locks",
"name": "AutoLock",
"roleDefinitionIds": [
"/providers/Microsoft.Authorization/roleDefinitions/18d7d88d-d35e-4fb5-a5c3-7773c20a72d9",
"/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
],
"existenceCondition": {
"field": "Microsoft.Authorization/locks/level",
"equals": "CanNotDelete"
},
"deployment": {
"properties": {
"mode": "incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"lockScope": {
"type": "string"
},
"assignmentId": {
"type": "string"
}
},
"resources": [
{
"name": "AutoLock",
"type": "Microsoft.Authorization/locks",
"apiVersion": "2020-05-01",
"scope": "[parameters('lockScope')]",
"properties": {
"level": "CanNotDelete",
"notes": "[concat('This lock was deployed automatically by Azure Policy to prevent the resource from accidental deletion. AssignmentId: ', parameters('assignmentId'))]"
}
}
]
},
"parameters": {
"lockScope": {
"value": "[concat(field('type'),'/', field('name'))]"
},
"assignmentId": {
"value": "[policy().assignmentId]"
}
}
}
}
}
}
}
}
}Bylaw7adb4ad7-b400-441f-afdc-aa5d3812f632.bylaw.ps1 · 30 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '7adb4ad7-b400-441f-afdc-aa5d3812f632' {
Properties @{
DisplayName = 'Deploy Purview account CanNotDelete lock'
Description = 'Deploys CanNotDelete lock on Purview account if not exists.'
Version = '1.0.0'
Category = 'Azure Purview'
Mode = 'All'
}
Parameter Effect @{
AllowedValues = @('DeployIfNotExists', 'AuditIfNotExists', 'Disabled')
Default = 'DeployIfNotExists'
DisplayName = 'Effect'
Description = 'DeployIfNotExists, AuditIfNotExists or Disabled the execution of the Policy'
}
Resource 'Microsoft.Purview/accounts'
DeployIfNotExists 'Microsoft.Authorization/locks' -Role 'User Access Administrator', 'Contributor' -Name 'AutoLock' -Effect (Param Effect) {
Require 'level is CanNotDelete' {
Field level | Must -Be 'CanNotDelete'
}
Deployment -TemplateFile './templates/7adb4ad7-b400-441f-afdc-aa5d3812f632.json' -Parameters ([ordered]@{
lockScope = (Arm '[concat(field(''type''),''/'', field(''name''))]')
assignmentId = (Arm '[policy().assignmentId]')
})
}
}Its deployment templates are written beside it:
templates/7adb4ad7-b400-441f-afdc-aa5d3812f632.json
Source: policyDefinitions/Azure Purview/deploy-purview-account-cannotdelete-lock/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw