Bylaw

Gallery › SQL › Azure Community Policy

Audit transparent data encryption status

Converted Policy AuditIfNotExists Disabled Mode Indexed Version 1.0.0

Audit transparent data encryption status for SQL databases

ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.

Azure Policy JSONazurepolicy.json · 60 lines
{
  "name": "516ec733-aa4d-408b-8e9b-9fc6230e4779",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Audit transparent data encryption status",
    "description": "Audit transparent data encryption status for SQL databases",
    "metadata": {
      "version": "1.0.0",
      "category": "SQL"
    },
    "mode": "Indexed",
    "parameters": {
      "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/transparentDataEncryption",
          "name": "current",
          "existenceCondition": {
            "anyOf": [
              {
                "field": "Microsoft.Sql/transparentDataEncryption.status",
                "equals": "enabled"
              },
              {
                "field": "Microsoft.Sql/servers/databases/transparentDataEncryption/state",
                "equals": "enabled"
              }
            ]
          }
        }
      }
    }
  }
}
Bylaw516ec733-aa4d-408b-8e9b-9fc6230e4779.bylaw.ps1 · 34 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '516ec733-aa4d-408b-8e9b-9fc6230e4779' {

    Properties @{
        DisplayName = 'Audit transparent data encryption status'
        Description = 'Audit transparent data encryption status for SQL databases'
        Version     = '1.0.0'
        Category    = 'SQL'
        Mode        = 'Indexed'
    }

    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/transparentDataEncryption' -Name 'current' -Effect (Param Effect) {
        Require 'transparentDataEncryption.status and state are as required' {
            AnyOf {
                Field 'Microsoft.Sql/transparentDataEncryption.status' | Must -Be 'enabled'
                Field state | Must -Be 'enabled'
            }
        }
    }
}

Source: policyDefinitions/SQL/audit-transparent-data-encryption-status/azurepolicy.json in Azure/Community-Policy, under the MIT licence.