Bylaw

Gallery › Monitoring › Azure Community Policy

Deny change of retention days in Log Analytics workspace

Converted Policy Audit Deny Disabled Mode All Version 1.0.0

Ensure the retention days for Log Analytics workspaces do not fall below the set threshold.

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

Azure Policy JSONazurepolicy.json · 53 lines
{
  "name": "c7eedeb9-bf27-40fa-91ce-4ccb1ae35edc",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Deny change of retention days in Log Analytics workspace",
    "description": "Ensure the retention days for Log Analytics workspaces do not fall below the set threshold.",
    "metadata": {
      "version": "1.0.0",
      "category": "Monitoring"
    },
    "mode": "All",
    "parameters": {
      "retentionInDays": {
        "type": "Integer",
        "metadata": {
          "displayName": "retentionInDays",
          "description": "retentionInDays"
        },
        "defaultValue": 179
      },
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Deny or Disabled the execution of the Policy"
        },
        "allowedValues": [
          "Deny",
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.OperationalInsights/workspaces"
          },
          {
            "field": "Microsoft.OperationalInsights/workspaces/retentionInDays",
            "lessOrEquals": "[parameters('retentionInDays')]"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylawc7eedeb9-bf27-40fa-91ce-4ccb1ae35edc.bylaw.ps1 · 33 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'c7eedeb9-bf27-40fa-91ce-4ccb1ae35edc' {

    Properties @{
        DisplayName = 'Deny change of retention days in Log Analytics workspace'
        Description = 'Ensure the retention days for Log Analytics workspaces do not fall below the set threshold.'
        Version     = '1.0.0'
        Category    = 'Monitoring'
        Mode        = 'All'
    }

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

    Resource 'Microsoft.OperationalInsights/workspaces' {

        Require 'retentionInDays is greater than the RetentionInDays parameter' {
            Field retentionInDays | Must -BeGreaterThan (Param RetentionInDays)
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/Monitoring/deny-change-of-retention-days-in-log-analytics-workspace/azurepolicy.json in Azure/Community-Policy, under the MIT licence.