Bylaw

Gallery › SQL › Azure Community Policy

Deny changes to SQLMI Long Term Backup Retention

Converted Policy Audit Deny Disabled Mode All Version 1.0.0

This policy denies any changes to backup long retention policies set on the SQL managed Instance. Replace 'notEquals' values with the timeframes required by the customer

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

Azure Policy JSONazurepolicy.json · 57 lines
{
  "name": "9d523ca4-114a-41ab-abe6-54d5213ff978",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Deny changes to SQLMI Long Term Backup Retention",
    "description": "This policy denies any changes to backup long retention policies set on the SQL managed Instance. Replace 'notEquals' values with the timeframes required by the customer ",
    "metadata": {
      "version": "1.0.0",
      "category": "SQL"
    },
    "mode": "All",
    "parameters": {
      "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": [
          {
            "AnyOf": [
              {
                "field": "Microsoft.Sql/managedInstances/databases/backupLongTermRetentionPolicies/default.weeklyRetention",
                "notEquals": "P4W"
              },
              {
                "field": "Microsoft.Sql/managedInstances/databases/backupLongTermRetentionPolicies/default.monthlyRetention",
                "notEquals": "P4W"
              },
              {
                "field": "Microsoft.Sql/managedInstances/databases/backupLongTermRetentionPolicies/default.yearlyRetention",
                "notEquals": "P12W"
              },
              {
                "field": "Microsoft.Sql/managedInstances/databases/backupLongTermRetentionPolicies/default.weekOfYear",
                "notEquals": 1
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylaw9d523ca4-114a-41ab-abe6-54d5213ff978.bylaw.ps1 · 39 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '9d523ca4-114a-41ab-abe6-54d5213ff978' {

    Properties @{
        DisplayName = 'Deny changes to SQLMI Long Term Backup Retention'
        Description = 'This policy denies any changes to backup long retention policies set on the SQL managed Instance. Replace ''notEquals'' values with the timeframes required by the customer '
        Version     = '1.0.0'
        Category    = 'SQL'
        Mode        = 'All'
    }

    Parameter Effect @{
        AllowedValues = @('Deny', 'Audit', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Deny, Audit or Disabled the execution of the Policy'
    }

    Resource * {

        Require 'default.weeklyRetention is P4W' {
            Field 'Microsoft.Sql/managedInstances/databases/backupLongTermRetentionPolicies/default.weeklyRetention' | Must -Be 'P4W'
        }

        Require 'default.monthlyRetention is P4W' {
            Field 'Microsoft.Sql/managedInstances/databases/backupLongTermRetentionPolicies/default.monthlyRetention' | Must -Be 'P4W'
        }

        Require 'default.yearlyRetention is P12W' {
            Field 'Microsoft.Sql/managedInstances/databases/backupLongTermRetentionPolicies/default.yearlyRetention' | Must -Be 'P12W'
        }

        Require 'default.weekOfYear is 1' {
            Field 'Microsoft.Sql/managedInstances/databases/backupLongTermRetentionPolicies/default.weekOfYear' | Must -Be 1
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/SQL/deny-changes-to-sqlmi-long-term-backup-retention/azurepolicy.json in Azure/Community-Policy, under the MIT licence.