Bylaw

Gallery › SQL › Azure Community Policy

Require SQL Server VM Auto Backup

Converted Policy Audit Deny Disabled Mode All Version 1.0.0

Require SQL Server Virtual Machines to have Auto Backup enabled/disabled

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

Azure Policy JSONazurepolicy.json · 53 lines
{
  "name": "f3587016-597a-447a-8910-c03c1a2aa9d4",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Require SQL Server VM Auto Backup",
    "description": "Require SQL Server Virtual Machines to have Auto Backup enabled/disabled",
    "metadata": {
      "version": "1.0.0",
      "category": "SQL"
    },
    "mode": "All",
    "parameters": {
      "autoBackupSetting": {
        "type": "Boolean",
        "metadata": {
          "displayName": "Auto Backup Setting",
          "description": "A boolean value for whether or not Auto Backup needs to be enabled on a SQL Server VM."
        },
        "defaultValue": false
      },
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Deny, Audit or Disabled the execution of the Policy"
        },
        "allowedValues": [
          "Deny",
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.SqlVirtualMachine/sqlVirtualMachines"
          },
          {
            "field": "SqlVirtualMachine/sqlVirtualMachines/autoBackupSettings.enable",
            "equals": "[parameters('autoBackupSetting')]"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylawf3587016-597a-447a-8910-c03c1a2aa9d4.bylaw.ps1 · 33 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'f3587016-597a-447a-8910-c03c1a2aa9d4' {

    Properties @{
        DisplayName = 'Require SQL Server VM Auto Backup'
        Description = 'Require SQL Server Virtual Machines to have Auto Backup enabled/disabled'
        Version     = '1.0.0'
        Category    = 'SQL'
        Mode        = 'All'
    }

    Parameter AutoBackupSetting @{
        Type        = 'Boolean'
        Default     = $false
        DisplayName = 'Auto Backup Setting'
        Description = 'A boolean value for whether or not Auto Backup needs to be enabled on a SQL Server VM.'
    }
    Parameter Effect @{
        AllowedValues = @('Deny', 'Audit', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Deny, Audit or Disabled the execution of the Policy'
    }

    Resource 'Microsoft.SqlVirtualMachine/sqlVirtualMachines' {

        Require 'autoBackupSettings.enable is not the AutoBackupSetting parameter' {
            Field 'SqlVirtualMachine/sqlVirtualMachines/autoBackupSettings.enable' -AllowUnknownAlias | Must -Not -Be (Param AutoBackupSetting) -IfPresent
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/SQL/require-sql-server-vm-auto-backup/azurepolicy.json in Azure/Community-Policy, under the MIT licence.