Bylaw

Gallery › Security Center › Azure built-in policies

SQL server-targeted autoprovisioning should be enabled for SQL servers on machines plan

Converted Policy AuditIfNotExists Disabled Mode All Version 1.0.0

To ensure your SQL VMs and Arc-enabled SQL Servers are protected, ensure the SQL-targeted Azure Monitoring Agent is configured to automatically deploy. This is also necessary if you've previously configured autoprovisioning of the Microsoft Monitoring Agent, as that component is being deprecated. Learn more: https://aka.ms/SQLAMAMigration

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

Azure Policy JSONMDC_DFSQL_AMA_Migration_Audit.json · 68 lines
{
  "properties": {
    "displayName": "SQL server-targeted autoprovisioning should be enabled for SQL servers on machines plan",
    "description": "To ensure your SQL VMs and Arc-enabled SQL Servers are protected, ensure the SQL-targeted Azure Monitoring Agent is configured to automatically deploy. This is also necessary if you've previously configured autoprovisioning of the Microsoft Monitoring Agent, as that component is being deprecated. Learn more: https://aka.ms/SQLAMAMigration",
    "policyType": "BuiltIn",
    "mode": "All",
    "version": "1.0.0",
    "metadata": {
      "version": "1.0.0",
      "category": "Security Center"
    },
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "AuditIfNotExists",
          "Disabled"
        ],
        "defaultValue": "AuditIfNotExists"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Security/pricings"
          },
          {
            "field": "name",
            "equals": "sqlservervirtualmachines"
          },
          {
            "field": "Microsoft.Security/pricings/pricingTier",
            "equals": "standard"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.Authorization/policyAssignments",
          "existenceCondition": {
            "anyOf": [
              {
                "field": "Microsoft.Authorization/policyAssignments/policyDefinitionId",
                "equals": "/providers/Microsoft.Authorization/policySetDefinitions/de01d381-bae9-4670-8870-786f89f49e26"
              },
              {
                "field": "Microsoft.Authorization/policyAssignments/policyDefinitionId",
                "equals": "/providers/Microsoft.Authorization/policySetDefinitions/d7c3ea3a-edf3-4bd5-bd64-d5b635b05393"
              }
            ]
          }
        }
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/c6283572-73bb-4deb-bf2c-7a2b8f7462cb",
  "name": "c6283572-73bb-4deb-bf2c-7a2b8f7462cb"
}
Bylawc6283572-73bb-4deb-bf2c-7a2b8f7462cb.bylaw.ps1 · 39 lines
# Converted from MDC_DFSQL_AMA_Migration_Audit.json by ConvertTo-Bylaw.
Policy 'c6283572-73bb-4deb-bf2c-7a2b8f7462cb' {

    Properties @{
        DisplayName   = 'SQL server-targeted autoprovisioning should be enabled for SQL servers on machines plan'
        Description   = 'To ensure your SQL VMs and Arc-enabled SQL Servers are protected, ensure the SQL-targeted Azure Monitoring Agent is configured to automatically deploy. This is also necessary if you''ve previously configured autoprovisioning of the Microsoft Monitoring Agent, as that component is being deprecated. Learn more: https://aka.ms/SQLAMAMigration'
        Version       = '1.0.0'
        Category      = 'Security Center'
        PolicyVersion = '1.0.0'
        Mode          = 'All'
    }

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

    Resource 'Microsoft.Security/pricings' {

        When {
            Field name | Must -Be 'sqlservervirtualmachines'
        }

        Require 'pricingTier is not standard' {
            Field pricingTier | Must -Not -Be 'standard' -IfPresent
        }
    }

    AuditIfNotExists 'Microsoft.Authorization/policyAssignments' -Effect (Param Effect) {
        Require 'policyDefinitionId is as required' {
            AnyOf {
                Field policyDefinitionId | Must -Be '/providers/Microsoft.Authorization/policySetDefinitions/de01d381-bae9-4670-8870-786f89f49e26'
                Field policyDefinitionId | Must -Be '/providers/Microsoft.Authorization/policySetDefinitions/d7c3ea3a-edf3-4bd5-bd64-d5b635b05393'
            }
        }
    }
}

Source: built-in-policies/policyDefinitions/Security Center/MDC_DFSQL_AMA_Migration_Audit.json in Azure/azure-policy, under the MIT licence.