Bylaw

Gallery › SQL › Azure Landing Zones Library

Deploy SQL Database security Alert Policies configuration with email admin accounts

Converted Policy DeployIfNotExists Disabled Mode Indexed Version 1.1.1

Deploy the security Alert Policies configuration with email admin accounts when it not exist in current configuration

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

Azure Policy JSONDeploy-Sql-SecurityAlertPolicies.alz_policy_definition.json · 121 lines
{
  "name": "Deploy-Sql-SecurityAlertPolicies",
  "properties": {
    "description": "Deploy the security Alert Policies configuration with email admin accounts when it not exist in current configuration",
    "displayName": "Deploy SQL Database security Alert Policies configuration with email admin accounts",
    "metadata": {
      "alzCloudEnvironments": [
        "AzureCloud",
        "AzureChinaCloud",
        "AzureUSGovernment"
      ],
      "category": "SQL",
      "source": "https://github.com/Azure/Enterprise-Scale/",
      "version": "1.1.1"
    },
    "mode": "Indexed",
    "parameters": {
      "effect": {
        "allowedValues": [
          "DeployIfNotExists",
          "Disabled"
        ],
        "defaultValue": "DeployIfNotExists",
        "metadata": {
          "description": "Enable or disable the execution of the policy",
          "displayName": "Effect"
        },
        "type": "String"
      },
      "emailAddresses": {
        "defaultValue": [
          "admin@contoso.com",
          "admin@fabrikam.com"
        ],
        "type": "Array"
      }
    },
    "policyRule": {
      "if": {
        "equals": "Microsoft.Sql/servers/databases",
        "field": "type"
      },
      "then": {
        "details": {
          "deployment": {
            "properties": {
              "mode": "Incremental",
              "parameters": {
                "emailAddresses": {
                  "value": "[parameters('emailAddresses')]"
                },
                "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": {
                  "emailAddresses": {
                    "type": "Array"
                  },
                  "location": {
                    "type": "String"
                  },
                  "sqlServerDataBaseName": {
                    "type": "String"
                  },
                  "sqlServerName": {
                    "type": "String"
                  }
                },
                "resources": [
                  {
                    "apiVersion": "2018-06-01-preview",
                    "name": "[concat(parameters('sqlServerName'),'/',parameters('sqlServerDataBaseName'),'/default')]",
                    "properties": {
                      "disabledAlerts": [
                        ""
                      ],
                      "emailAccountAdmins": true,
                      "emailAddresses": "[parameters('emailAddresses')]",
                      "retentionDays": 0,
                      "state": "Enabled",
                      "storageAccountAccessKey": "",
                      "storageEndpoint": null
                    },
                    "type": "Microsoft.Sql/servers/databases/securityAlertPolicies"
                  }
                ],
                "variables": {}
              }
            }
          },
          "existenceCondition": {
            "allOf": [
              {
                "equals": "Enabled",
                "field": "Microsoft.Sql/servers/databases/securityAlertPolicies/state"
              }
            ]
          },
          "roleDefinitionIds": [
            "/providers/Microsoft.Authorization/roleDefinitions/056cd41c-7e88-42e1-933e-88ba6a50c9c3"
          ],
          "type": "Microsoft.Sql/servers/databases/securityAlertPolicies"
        },
        "effect": "[parameters('effect')]"
      }
    },
    "policyType": "Custom"
  },
  "type": "Microsoft.Authorization/policyDefinitions"
}
BylawDeploy-Sql-SecurityAlertPolicies.bylaw.ps1 · 37 lines
# Converted from Deploy-Sql-SecurityAlertPolicies.alz_policy_definition.json by ConvertTo-Bylaw.
Policy 'Deploy-Sql-SecurityAlertPolicies' {

    Properties @{
        DisplayName = 'Deploy SQL Database security Alert Policies configuration with email admin accounts'
        Description = 'Deploy the security Alert Policies configuration with email admin accounts when it not exist in current configuration'
        Category    = 'SQL'
        Version     = '1.1.1'
        Mode        = 'Indexed'
        Metadata    = [ordered]@{ alzCloudEnvironments = @('AzureCloud', 'AzureChinaCloud', 'AzureUSGovernment'); source = 'https://github.com/Azure/Enterprise-Scale/' }
    }

    Parameter Effect @{
        AllowedValues = @('DeployIfNotExists', 'Disabled')
        Default       = 'DeployIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }
    Parameter EmailAddresses @{
        Type    = 'Array'
        Default = @('admin@contoso.com', 'admin@fabrikam.com')
    }

    Resource 'Microsoft.Sql/servers/databases'

    DeployIfNotExists 'Microsoft.Sql/servers/databases/securityAlertPolicies' -Role 'SQL Security Manager' -Effect (Param Effect) {
        Require 'state is Enabled' {
            Field state | Must -Be 'Enabled'
        }
        Deployment -TemplateFile './templates/Deploy-Sql-SecurityAlertPolicies.json' -Parameters ([ordered]@{
                emailAddresses        = (Param EmailAddresses)
                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-SecurityAlertPolicies.alz_policy_definition.json in Azure/Azure-Landing-Zones-Library, under the MIT licence.