Gallery › General › Azure Community Policy
Protect selected resources from deletion
Doesn't convert yet Policy DenyAction Disabled Mode Indexed Version 1.0.0
This policy protects selected resource types from accidental or malicious deletion.
ConvertTo-Bylaw can't convert this policy yet:
- BYL6003 The converted file doesn't compile, which is a ConvertTo-Bylaw bug: BYL1014: Policy '927f91cf-9e9f-4d95-9deb-1579aed07ace' stopped because of an error: A positional parameter cannot be found that accepts argument 'Cascadebehavior'. BYL1006: Policy '927f91cf-9e9f-4d95-9deb-1579aed07ace' has no Effect. Add for example: Effect Deny, Effect (Param Effect), a Modify or Append block, DenyAction Delete, Manual, or AuditIfNotExists or DeployIfNotExists ... { }.
Azure Policy JSONazurepolicy.json · 67 lines
{
"name": "927f91cf-9e9f-4d95-9deb-1579aed07ace",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Protect selected resources from deletion",
"description": "This policy protects selected resource types from accidental or malicious deletion.",
"mode": "Indexed",
"metadata": {
"version": "1.0.0",
"category": "General"
},
"version": "1.0.0",
"parameters": {
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "Deny, or Disables the execution of the Policy."
},
"allowedValues": [
"DenyAction",
"Disabled"
],
"defaultValue": "DenyAction"
},
"cascadeBehavior": {
"type": "String",
"metadata": {
"displayName": "Cascade Behavior",
"description": "Defines which behavior is followed when a resource is implicitly deleted when a resource group is removed."
},
"allowedValues": [
"deny",
"allow"
],
"defaultValue": "deny"
},
"protectedResourceTypes": {
"type": "Array",
"metadata": {
"displayName": "Protected Resource Types",
"description": "Array of resource types to protect from deletion (e.g., ['Microsoft.Network/vpnSites', 'Microsoft.Storage/storageAccounts'])."
}
}
},
"policyRule": {
"if": {
"field": "type",
"in": "[parameters('protectedResourceTypes')]"
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"actionNames": [
"delete"
],
"cascadeBehaviors": {
"resourceGroup": "[parameters('cascadeBehavior')]"
}
}
}
},
"versions": [
"1.0.0"
]
}
}Source: policyDefinitions/General/protect-resources-with-deny-action/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw