Bylaw

Gallery › SQL › Azure built-in policies

Geo-redundant backup should be enabled for Azure Database for MySQL

Converted Policy Audit Disabled Mode Indexed Version 1.0.1

Azure Database for MySQL allows you to choose the redundancy option for your database server. It can be set to a geo-redundant backup storage in which the data is not only stored within the region in which your server is hosted, but is also replicated to a paired region to provide recovery option in case of a region failure. Configuring geo-redundant storage for backup is only allowed during server create.

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

Azure Policy JSONGeoRedundant_DBForMySQL_Audit.json · 49 lines
{
  "properties": {
    "displayName": "Geo-redundant backup should be enabled for Azure Database for MySQL",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Azure Database for MySQL allows you to choose the redundancy option for your database server. It can be set to a geo-redundant backup storage in which the data is not only stored within the region in which your server is hosted, but is also replicated to a paired region to provide recovery option in case of a region failure. Configuring geo-redundant storage for backup is only allowed during server create.",
    "metadata": {
      "version": "1.0.1",
      "category": "SQL"
    },
    "version": "1.0.1",
    "parameters": {
      "effect": {
        "type": "string",
        "defaultValue": "Audit",
        "allowedValues": [
          "Audit",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.DBforMySQL/servers"
          },
          {
            "field": "Microsoft.DBforMySQL/servers/storageProfile.geoRedundantBackup",
            "notEquals": "Enabled"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.1"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/82339799-d096-41ae-8538-b108becf0970",
  "name": "82339799-d096-41ae-8538-b108becf0970"
}
Bylaw82339799-d096-41ae-8538-b108becf0970.bylaw.ps1 · 29 lines
# Converted from GeoRedundant_DBForMySQL_Audit.json by ConvertTo-Bylaw.
Policy '82339799-d096-41ae-8538-b108becf0970' {

    Properties @{
        DisplayName   = 'Geo-redundant backup should be enabled for Azure Database for MySQL'
        Description   = 'Azure Database for MySQL allows you to choose the redundancy option for your database server. It can be set to a geo-redundant backup storage in which the data is not only stored within the region in which your server is hosted, but is also replicated to a paired region to provide recovery option in case of a region failure. Configuring geo-redundant storage for backup is only allowed during server create.'
        Version       = '1.0.1'
        Category      = 'SQL'
        PolicyVersion = '1.0.1'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        Type          = 'string'
        AllowedValues = @('Audit', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }

    Resource 'Microsoft.DBforMySQL/servers' {

        Require 'storageProfile.geoRedundantBackup is Enabled' {
            Field storageProfile.geoRedundantBackup | Must -Be 'Enabled'
        }
    }

    Effect (Param Effect)
}

Source: built-in-policies/policyDefinitions/SQL/GeoRedundant_DBForMySQL_Audit.json in Azure/azure-policy, under the MIT licence.