Bylaw

Gallery › Compute › Azure built-in policies

[Deprecated]: Resource logs in Virtual Machine Scale Sets should be enabled

Converted Policy AuditIfNotExists Disabled Mode Indexed Version 2.2.0-deprecated Deprecated

This policy definition is no longer the recommended way to achieve its intent. Instead of continuing to use this policy, we recommend you assign this replacement policy with policy ID a3a6ea0c-e018-4933-9ef0-5aaa1501449b. Learn more about policy definition deprecation at aka.ms/policydefdeprecation

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

Azure Policy JSONServiceFabric_and_VMSS_AuditVMSSDiagnostics.json · 125 lines
{
  "properties": {
    "displayName": "[Deprecated]: Resource logs in Virtual Machine Scale Sets should be enabled",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "This policy definition is no longer the recommended way to achieve its intent. Instead of continuing to use this policy, we recommend you assign this replacement policy with policy ID a3a6ea0c-e018-4933-9ef0-5aaa1501449b. Learn more about policy definition deprecation at aka.ms/policydefdeprecation",
    "metadata": {
      "version": "2.2.0-deprecated",
      "category": "Compute",
      "deprecated": true
    },
    "version": "2.2.0",
    "parameters": {
      "effect": {
        "type": "string",
        "defaultValue": "Disabled",
        "allowedValues": [
          "AuditIfNotExists",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      },
      "includeAKSClusters": {
        "type": "Boolean",
        "metadata": {
          "displayName": "Include AKS Clusters",
          "description": "Whether to include AKS Clusters to resource logs extension - True or False"
        },
        "defaultValue": false
      }
    },
    "policyRule": {
      "if": {
        "anyOf": [
          {
            "allOf": [
              {
                "field": "type",
                "equals": "Microsoft.Compute/virtualMachineScaleSets"
              },
              {
                "value": "[parameters('includeAKSClusters')]",
                "equals": true
              }
            ]
          },
          {
            "allOf": [
              {
                "field": "type",
                "equals": "Microsoft.Compute/virtualMachineScaleSets"
              },
              {
                "value": "[parameters('includeAKSClusters')]",
                "equals": false
              },
              {
                "field": "Microsoft.Compute/imagePublisher",
                "notEquals": "microsoft-aks"
              },
              {
                "field": "Microsoft.Compute/imageOffer",
                "notEquals": "aks"
              },
              {
                "field": "Microsoft.Compute/imageSKU",
                "notLike": "aks*"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.Compute/virtualMachineScaleSets/extensions",
          "existenceCondition": {
            "anyOf": [
              {
                "field": "Microsoft.Compute/virtualMachineScaleSets/extensions/publisher",
                "equals": "Microsoft.AKS"
              },
              {
                "allOf": [
                  {
                    "field": "Microsoft.Compute/virtualMachineScaleSets/extensions/type",
                    "equals": "IaaSDiagnostics"
                  },
                  {
                    "field": "Microsoft.Compute/virtualMachineScaleSets/extensions/publisher",
                    "equals": "Microsoft.Azure.Diagnostics"
                  }
                ]
              },
              {
                "allOf": [
                  {
                    "field": "Microsoft.Compute/virtualMachineScaleSets/extensions/type",
                    "equals": "LinuxDiagnostic"
                  },
                  {
                    "field": "Microsoft.Compute/virtualMachineScaleSets/extensions/publisher",
                    "in": [
                      "Microsoft.OSTCExtensions",
                      "Microsoft.Azure.Diagnostics"
                    ]
                  }
                ]
              }
            ]
          }
        }
      }
    },
    "versions": [
      "2.2.0",
      "2.1.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/7c1b1214-f927-48bf-8882-84f0af6588b1",
  "name": "7c1b1214-f927-48bf-8882-84f0af6588b1"
}
Bylaw7c1b1214-f927-48bf-8882-84f0af6588b1.bylaw.ps1 · 63 lines
# Converted from ServiceFabric_and_VMSS_AuditVMSSDiagnostics.json by ConvertTo-Bylaw.
Policy '7c1b1214-f927-48bf-8882-84f0af6588b1' {

    Properties @{
        DisplayName   = '[Deprecated]: Resource logs in Virtual Machine Scale Sets should be enabled'
        Description   = 'This policy definition is no longer the recommended way to achieve its intent. Instead of continuing to use this policy, we recommend you assign this replacement policy with policy ID a3a6ea0c-e018-4933-9ef0-5aaa1501449b. Learn more about policy definition deprecation at aka.ms/policydefdeprecation'
        Version       = '2.2.0-deprecated'
        Category      = 'Compute'
        Deprecated    = $true
        PolicyVersion = '2.2.0'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        Type          = 'string'
        AllowedValues = @('AuditIfNotExists', 'Disabled')
        Default       = 'Disabled'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }
    Parameter IncludeAKSClusters @{
        Type        = 'Boolean'
        Default     = $false
        DisplayName = 'Include AKS Clusters'
        Description = 'Whether to include AKS Clusters to resource logs extension - True or False'
    }

    Resource * {

        Require 'type is as required' {
            AnyOf {
                Field type | Must -Not -Be 'Microsoft.Compute/virtualMachineScaleSets' -IfPresent
                Param IncludeAKSClusters | Must -Not -Be $true
            }
        }

        Require 'type, imagePublisher, imageOffer and 1 more are as required' {
            AnyOf {
                Field type | Must -Not -Be 'Microsoft.Compute/virtualMachineScaleSets' -IfPresent
                Param IncludeAKSClusters | Must -Not -Be $false
                Field 'Microsoft.Compute/imagePublisher' | Must -Be 'microsoft-aks'
                Field 'Microsoft.Compute/imageOffer' | Must -Be 'aks'
                Field 'Microsoft.Compute/imageSKU' | Must -BeLike 'aks*'
            }
        }
    }

    AuditIfNotExists 'Microsoft.Compute/virtualMachineScaleSets/extensions' -Effect (Param Effect) {
        Require 'publisher and type are as required' {
            AnyOf {
                Field publisher | Must -Be 'Microsoft.AKS'
                AllOf {
                    Field 'Microsoft.Compute/virtualMachineScaleSets/extensions/type' | Must -Be 'IaaSDiagnostics'
                    Field publisher | Must -Be 'Microsoft.Azure.Diagnostics'
                }
                AllOf {
                    Field 'Microsoft.Compute/virtualMachineScaleSets/extensions/type' | Must -Be 'LinuxDiagnostic'
                    Field publisher | Must -BeIn @('Microsoft.OSTCExtensions', 'Microsoft.Azure.Diagnostics')
                }
            }
        }
    }
}

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