Gallery › Storage › Azure Community Policy
Audit - StorageAccounts Should Have Lifecycle Policy Enabled
Converted Policy AuditIfNotExists Disabled Mode All Version 1.0.0
This policy audits storage accounts that do not have at least one management policy of type lifecycle enabled.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONazurepolicy.json · 58 lines
{
"name": "bc1e3f2c-692d-4e3e-ab47-9273a71d8079",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Audit - StorageAccounts Should Have Lifecycle Policy Enabled",
"description": "This policy audits storage accounts that do not have at least one management policy of type lifecycle enabled.",
"metadata": {
"version": "1.0.0",
"category": "Storage"
},
"mode": "All",
"parameters": {
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "AuditIfNotExists or Disabled the execution of the Policy"
},
"allowedValues": [
"AuditIfNotExists",
"Disabled"
],
"defaultValue": "AuditIfNotExists"
}
},
"policyRule": {
"if": {
"field": "type",
"equals": "Microsoft.Storage/storageAccounts"
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.Storage/storageAccounts/managementPolicies",
"name": "[concat(field('name'), '/default')]",
"existenceCondition": {
"count": {
"field": "Microsoft.Storage/storageAccounts/managementPolicies/policy.rules[*]",
"where": {
"allOf": [
{
"field": "Microsoft.Storage/storageAccounts/managementPolicies/policy.rules[*].enabled",
"equals": true
},
{
"field": "Microsoft.Storage/storageAccounts/managementPolicies/policy.rules[*].type",
"equals": "Lifecycle"
}
]
}
},
"greater": 0
}
}
}
}
}
}Bylawbc1e3f2c-692d-4e3e-ab47-9273a71d8079.bylaw.ps1 · 29 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'bc1e3f2c-692d-4e3e-ab47-9273a71d8079' {
Properties @{
DisplayName = 'Audit - StorageAccounts Should Have Lifecycle Policy Enabled'
Description = 'This policy audits storage accounts that do not have at least one management policy of type lifecycle enabled.'
Version = '1.0.0'
Category = 'Storage'
Mode = 'All'
}
Parameter Effect @{
AllowedValues = @('AuditIfNotExists', 'Disabled')
Default = 'AuditIfNotExists'
DisplayName = 'Effect'
Description = 'AuditIfNotExists or Disabled the execution of the Policy'
}
Resource 'Microsoft.Storage/storageAccounts'
AuditIfNotExists 'Microsoft.Storage/storageAccounts/managementPolicies' -Name (Arm '[concat(field(''name''), ''/default'')]') -Effect (Param Effect) {
Require 'policy.rules, enabled and type are as required' {
Count 'policy.rules[*]' -Where {
Field enabled | Must -Be $true
Field type | Must -Be 'Lifecycle'
} | Must -BeGreaterThan 0
}
}
}Source: policyDefinitions/Storage/audit-storageaccounts-should-have-lifecycle-policy-enabled/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw