Bylaw

Gallery › SQL › Azure built-in policies

Transparent Data Encryption on SQL databases should be enabled

Converted Policy AuditIfNotExists Disabled Mode Indexed Version 2.0.0

Transparent data encryption should be enabled to protect data-at-rest and meet compliance requirements

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

Azure Policy JSONSqlDBEncryption_Audit.json · 65 lines
{
  "properties": {
    "displayName": "Transparent Data Encryption on SQL databases should be enabled",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Transparent data encryption should be enabled to protect data-at-rest and meet compliance requirements",
    "metadata": {
      "version": "2.0.0",
      "category": "SQL"
    },
    "version": "2.0.0",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable 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"
              }
            ]
          }
        }
      }
    },
    "versions": [
      "2.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/17k78e20-9358-41c9-923c-fb736d382a12",
  "name": "17k78e20-9358-41c9-923c-fb736d382a12"
}
Bylaw17k78e20-9358-41c9-923c-fb736d382a12.bylaw.ps1 · 35 lines
# Converted from SqlDBEncryption_Audit.json by ConvertTo-Bylaw.
Policy '17k78e20-9358-41c9-923c-fb736d382a12' {

    Properties @{
        DisplayName   = 'Transparent Data Encryption on SQL databases should be enabled'
        Description   = 'Transparent data encryption should be enabled to protect data-at-rest and meet compliance requirements'
        Version       = '2.0.0'
        Category      = 'SQL'
        PolicyVersion = '2.0.0'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('AuditIfNotExists', 'Disabled')
        Default       = 'AuditIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable 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: built-in-policies/policyDefinitions/SQL/SqlDBEncryption_Audit.json in Azure/azure-policy, under the MIT licence.