Gallery › Storage › Azure Community Policy
enable-blob-softdelete-30days
Converted Policy AuditIfNotExists DeployIfNotExists Disabled Mode All Version 1.0.0
need to add description
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONazurepolicy.json · 122 lines
{
"name": "dcff4ec6-f894-4975-964f-5e41f8db90a3",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "enable-blob-softdelete-30days",
"description": "need to add description",
"metadata": {
"version": "1.0.0",
"category": "Storage"
},
"mode": "All",
"parameters": {
"retentionInDays": {
"type": "Integer",
"metadata": {
"displayName": "Retention in days",
"description": "This defines how long the deleted object should be retained for"
},
"defaultValue": 30
},
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "DeployIfNotExists, AuditIfNotExists or Disabled the execution of the Policy"
},
"allowedValues": [
"DeployIfNotExists",
"AuditIfNotExists",
"Disabled"
],
"defaultValue": "DeployIfNotExists"
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Storage/storageAccounts"
},
{
"field": "kind",
"in": [
"Storage",
"StorageV2",
"BlobStorage",
"BlockBlobStorage"
]
}
]
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.Storage/storageAccounts/blobServices",
"roleDefinitionIds": [
"/providers/Microsoft.Authorization/roleDefinitions/17d1049b-9a84-46fb-8f53-869881c3d3ab"
],
"existenceCondition": {
"allOf": [
{
"field": "Microsoft.Storage/storageAccounts/blobServices/default.deleteRetentionPolicy.enabled",
"equals": true
},
{
"field": "Microsoft.Storage/storageAccounts/blobServices/deleteRetentionPolicy.days",
"equals": "[parameters('retentionInDays')]"
}
]
},
"deployment": {
"properties": {
"mode": "incremental",
"parameters": {
"accountName": {
"value": "[field('name')]"
},
"storageAccountName": {
"value": "[field('name')]"
},
"retentionInDays": {
"value": "[parameters('retentionInDays')]"
}
},
"template": {
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"accountName": {
"type": "string"
},
"storageAccountName": {
"type": "string"
},
"retentionInDays": {
"type": "int"
}
},
"resources": [
{
"name": "[concat(parameters('storageAccountName'), '/default')]",
"type": "Microsoft.Storage/storageAccounts/blobServices",
"apiVersion": "2019-06-01",
"properties": {
"deleteRetentionPolicy": {
"enabled": true,
"days": "[parameters('retentionInDays')]"
}
}
}
],
"variables": {},
"outputs": {}
}
}
}
}
}
}
}
}Bylawdcff4ec6-f894-4975-964f-5e41f8db90a3.bylaw.ps1 · 43 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'dcff4ec6-f894-4975-964f-5e41f8db90a3' {
Properties @{
DisplayName = 'enable-blob-softdelete-30days'
Description = 'need to add description'
Version = '1.0.0'
Category = 'Storage'
Mode = 'All'
}
Parameter RetentionInDays @{
Type = 'Integer'
Default = 30
DisplayName = 'Retention in days'
Description = 'This defines how long the deleted object should be retained for'
}
Parameter Effect @{
AllowedValues = @('DeployIfNotExists', 'AuditIfNotExists', 'Disabled')
Default = 'DeployIfNotExists'
DisplayName = 'Effect'
Description = 'DeployIfNotExists, AuditIfNotExists or Disabled the execution of the Policy'
}
Resource 'Microsoft.Storage/storageAccounts' {
Require 'kind is not one of 4 values' {
Field kind | Must -Not -BeIn @('Storage', 'StorageV2', 'BlobStorage', 'BlockBlobStorage') -IfPresent
}
}
DeployIfNotExists 'Microsoft.Storage/storageAccounts/blobServices' -Role 'Storage Account Contributor' -Effect (Param Effect) {
Require 'default.deleteRetentionPolicy.enabled and deleteRetentionPolicy.days are as required' {
Field default.deleteRetentionPolicy.enabled | Must -Be $true
Field deleteRetentionPolicy.days | Must -Be (Param RetentionInDays)
}
Deployment -TemplateFile './templates/dcff4ec6-f894-4975-964f-5e41f8db90a3.json' -Parameters ([ordered]@{
accountName = (Arm '[field(''name'')]')
storageAccountName = (Arm '[field(''name'')]')
retentionInDays = (Param RetentionInDays)
})
}
}Its deployment templates are written beside it:
templates/dcff4ec6-f894-4975-964f-5e41f8db90a3.json
Source: policyDefinitions/Storage/enable-blob-softdelete-30days/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw