Bylaw

Gallery › SQL › Azure Landing Zones Library

[Deprecated] Deploy SQL Database Transparent Data Encryption

Converted Policy DeployIfNotExists Disabled Mode Indexed Version 1.1.1-deprecated Deprecated

Deploy the Transparent Data Encryption when it is not enabled in the deployment. Please use this policy instead https://www.azadvertizer.net/azpolicyadvertizer/86a912f6-9a06-4e26-b447-11b16ba8659f.html

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

Azure Policy JSONDeploy-Sql-Tde.alz_policy_definition.json · 124 lines
{
  "name": "Deploy-Sql-Tde",
  "properties": {
    "description": "Deploy the Transparent Data Encryption when it is not enabled in the deployment. Please use this policy instead https://www.azadvertizer.net/azpolicyadvertizer/86a912f6-9a06-4e26-b447-11b16ba8659f.html",
    "displayName": "[Deprecated] Deploy SQL Database Transparent Data Encryption",
    "metadata": {
      "alzCloudEnvironments": [
        "AzureCloud",
        "AzureChinaCloud",
        "AzureUSGovernment"
      ],
      "category": "SQL",
      "deprecated": true,
      "source": "https://github.com/Azure/Enterprise-Scale/",
      "supersededBy": "86a912f6-9a06-4e26-b447-11b16ba8659f",
      "version": "1.1.1-deprecated"
    },
    "mode": "Indexed",
    "parameters": {
      "effect": {
        "allowedValues": [
          "DeployIfNotExists",
          "Disabled"
        ],
        "defaultValue": "DeployIfNotExists",
        "metadata": {
          "description": "Enable or disable the execution of the policy",
          "displayName": "Effect"
        },
        "type": "String"
      },
      "excludedDatabases": {
        "defaultValue": [
          "master",
          "model",
          "tempdb",
          "msdb",
          "resource"
        ],
        "metadata": {
          "description": "Array of databases that are excluded from this policy",
          "displayName": "Excluded Databases"
        },
        "type": "Array"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "equals": "Microsoft.Sql/servers/databases",
            "field": "type"
          },
          {
            "field": "name",
            "notIn": "[parameters('excludedDatabases')]"
          }
        ]
      },
      "then": {
        "details": {
          "deployment": {
            "properties": {
              "mode": "Incremental",
              "parameters": {
                "location": {
                  "value": "[field('location')]"
                },
                "sqlServerDataBaseName": {
                  "value": "[field('name')]"
                },
                "sqlServerName": {
                  "value": "[first(split(field('fullname'),'/'))]"
                }
              },
              "template": {
                "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                "contentVersion": "1.0.0.0",
                "outputs": {},
                "parameters": {
                  "location": {
                    "type": "String"
                  },
                  "sqlServerDataBaseName": {
                    "type": "String"
                  },
                  "sqlServerName": {
                    "type": "String"
                  }
                },
                "resources": [
                  {
                    "apiVersion": "2014-04-01",
                    "name": "[concat( parameters('sqlServerName'),'/',parameters('sqlServerDataBaseName'),'/current')]",
                    "properties": {
                      "status": "Enabled"
                    },
                    "type": "Microsoft.Sql/servers/databases/transparentDataEncryption"
                  }
                ],
                "variables": {}
              }
            }
          },
          "existenceCondition": {
            "allOf": [
              {
                "equals": "Enabled",
                "field": "Microsoft.Sql/transparentDataEncryption.status"
              }
            ]
          },
          "roleDefinitionIds": [
            "/providers/Microsoft.Authorization/roleDefinitions/056cd41c-7e88-42e1-933e-88ba6a50c9c3"
          ],
          "type": "Microsoft.Sql/servers/databases/transparentDataEncryption"
        },
        "effect": "[parameters('effect')]"
      }
    },
    "policyType": "Custom"
  },
  "type": "Microsoft.Authorization/policyDefinitions"
}
BylawDeploy-Sql-Tde.bylaw.ps1 · 44 lines
# Converted from Deploy-Sql-Tde.alz_policy_definition.json by ConvertTo-Bylaw.
Policy 'Deploy-Sql-Tde' {

    Properties @{
        DisplayName = '[Deprecated] Deploy SQL Database Transparent Data Encryption'
        Description = 'Deploy the Transparent Data Encryption when it is not enabled in the deployment. Please use this policy instead https://www.azadvertizer.net/azpolicyadvertizer/86a912f6-9a06-4e26-b447-11b16ba8659f.html'
        Category    = 'SQL'
        Deprecated  = $true
        Version     = '1.1.1-deprecated'
        Mode        = 'Indexed'
        Metadata    = [ordered]@{ alzCloudEnvironments = @('AzureCloud', 'AzureChinaCloud', 'AzureUSGovernment'); source = 'https://github.com/Azure/Enterprise-Scale/'; supersededBy = '86a912f6-9a06-4e26-b447-11b16ba8659f' }
    }

    Parameter Effect @{
        AllowedValues = @('DeployIfNotExists', 'Disabled')
        Default       = 'DeployIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }
    Parameter ExcludedDatabases @{
        Type        = 'Array'
        Default     = @('master', 'model', 'tempdb', 'msdb', 'resource')
        DisplayName = 'Excluded Databases'
        Description = 'Array of databases that are excluded from this policy'
    }

    Resource 'Microsoft.Sql/servers/databases' {

        Require 'name is one of the ExcludedDatabases parameter' {
            Field name | Must -BeIn (Param ExcludedDatabases)
        }
    }

    DeployIfNotExists 'Microsoft.Sql/servers/databases/transparentDataEncryption' -Role 'SQL Security Manager' -Effect (Param Effect) {
        Require 'transparentDataEncryption.status is Enabled' {
            Field 'Microsoft.Sql/transparentDataEncryption.status' | Must -Be 'Enabled'
        }
        Deployment -TemplateFile './templates/Deploy-Sql-Tde.json' -Parameters ([ordered]@{
                location              = (Arm '[field(''location'')]')
                sqlServerDataBaseName = (Arm '[field(''name'')]')
                sqlServerName         = (Arm '[first(split(field(''fullname''),''/''))]')
            })
    }
}

Its deployment templates are written beside it:

Source: policy_definitions/Deploy-Sql-Tde.alz_policy_definition.json in Azure/Azure-Landing-Zones-Library, under the MIT licence.