Gallery › SQL › Azure Community Policy
Audit SQL DB Level Audit Setting
Converted Policy AuditIfNotExists Disabled Mode All Version 1.0.0
Audit DB level audit setting for SQL databases
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONazurepolicy.json · 62 lines
{
"name": "fe53aca3-4eeb-449f-a2d5-aad2d728481e",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Audit SQL DB Level Audit Setting",
"description": "Audit DB level audit setting for SQL databases",
"metadata": {
"version": "1.0.0",
"category": "SQL"
},
"mode": "All",
"parameters": {
"setting": {
"type": "String",
"allowedValues": [
"enabled",
"disabled"
],
"metadata": {
"displayName": "Audit Setting"
}
},
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "AuditIfNotExists or Disabled the execution of the Policy"
},
"allowedValues": [
"AuditIfNotExists",
"Disabled"
],
"defaultValue": "AuditIfNotExists"
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.SQL/servers/databases"
},
{
"field": "name",
"notEquals": "master"
}
]
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.SQL/servers/databases/auditingSettings",
"name": "default",
"existenceCondition": {
"field": "Microsoft.Sql/auditingSettings.state",
"equals": "[parameters('setting')]"
}
}
}
}
}
}Bylawfe53aca3-4eeb-449f-a2d5-aad2d728481e.bylaw.ps1 · 36 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'fe53aca3-4eeb-449f-a2d5-aad2d728481e' {
Properties @{
DisplayName = 'Audit SQL DB Level Audit Setting'
Description = 'Audit DB level audit setting for SQL databases'
Version = '1.0.0'
Category = 'SQL'
Mode = 'All'
}
Parameter Setting @{
Type = 'String'
AllowedValues = @('enabled', 'disabled')
DisplayName = 'Audit Setting'
}
Parameter Effect @{
AllowedValues = @('AuditIfNotExists', 'Disabled')
Default = 'AuditIfNotExists'
DisplayName = 'Effect'
Description = 'AuditIfNotExists or Disabled the execution of the Policy'
}
Resource 'Microsoft.SQL/servers/databases' {
Require 'name is master' {
Field name | Must -Be 'master'
}
}
AuditIfNotExists 'Microsoft.SQL/servers/databases/auditingSettings' -Name 'default' -Effect (Param Effect) {
Require 'auditingSettings.state is the Setting parameter' {
Field 'Microsoft.Sql/auditingSettings.state' | Must -Be (Param Setting)
}
}
}Source: policyDefinitions/SQL/audit-sql-db-level-audit-setting/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw