Bylaw

Gallery › Monitoring › Azure built-in policies

[Deprecated]: Deploy Log Analytics extension for Linux VMs. See deprecation notice below

Converted Policy DeployIfNotExists Disabled Mode Indexed Version 3.1.0-deprecated Deprecated

This policy definition is deprecated because OMS Agent was deprecated on August 31, 2024. While there is not a specific replacement policy, we have various policies available based on the VM setup that can be found under Azure Monitor Agent/DCRA Linux. 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 JSONLogAnalyticsExtension_Linux_VM_DINE.json · 401 lines
{
  "properties": {
    "displayName": "[Deprecated]: Deploy Log Analytics extension for Linux VMs. See deprecation notice below",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "This policy definition is deprecated because OMS Agent was deprecated on August 31, 2024. While there is not a specific replacement policy, we have various policies available based on the VM setup that can be found under Azure Monitor Agent/DCRA Linux. Learn more about policy definition deprecation at aka.ms/policydefdeprecation.",
    "metadata": {
      "version": "3.1.0-deprecated",
      "category": "Monitoring",
      "deprecated": true
    },
    "version": "3.1.0",
    "parameters": {
      "logAnalytics": {
        "type": "String",
        "metadata": {
          "displayName": "Log Analytics workspace",
          "description": "Select Log Analytics workspace from dropdown list. If this workspace is outside of the scope of the assignment you must manually grant 'Log Analytics Contributor' permissions (or similar) to the policy assignment's principal ID.",
          "strongType": "omsWorkspace",
          "assignPermissions": true
        }
      },
      "listOfImageIdToInclude": {
        "type": "Array",
        "defaultValue": [],
        "metadata": {
          "displayName": "Optional: List of VM images that have supported Linux OS to add to scope",
          "description": "Example value: '/subscriptions/<subscriptionId>/resourceGroups/YourResourceGroup/providers/Microsoft.Compute/images/ContosoStdImage'"
        }
      },
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy."
        },
        "allowedValues": [
          "DeployIfNotExists",
          "Disabled"
        ],
        "defaultValue": "Disabled"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Compute/virtualMachines"
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.Compute/imageId",
                "in": "[parameters('listOfImageIdToInclude')]"
              },
              {
                "allOf": [
                  {
                    "field": "Microsoft.Compute/imagePublisher",
                    "equals": "RedHat"
                  },
                  {
                    "field": "Microsoft.Compute/imageOffer",
                    "in": [
                      "RHEL",
                      "RHEL-SAP-HANA"
                    ]
                  },
                  {
                    "anyOf": [
                      {
                        "field": "Microsoft.Compute/imageSKU",
                        "like": "6.*"
                      },
                      {
                        "field": "Microsoft.Compute/imageSKU",
                        "like": "7*"
                      },
                      {
                        "field": "Microsoft.Compute/imageSKU",
                        "like": "8*"
                      }
                    ]
                  }
                ]
              },
              {
                "allOf": [
                  {
                    "field": "Microsoft.Compute/imagePublisher",
                    "equals": "SUSE"
                  },
                  {
                    "anyOf": [
                      {
                        "allOf": [
                          {
                            "field": "Microsoft.Compute/imageOffer",
                            "in": [
                              "SLES",
                              "SLES-HPC",
                              "SLES-HPC-Priority",
                              "SLES-SAP",
                              "SLES-SAP-BYOS",
                              "SLES-Priority",
                              "SLES-BYOS",
                              "SLES-SAPCAL",
                              "SLES-Standard"
                            ]
                          },
                          {
                            "anyOf": [
                              {
                                "field": "Microsoft.Compute/imageSKU",
                                "like": "12*"
                              },
                              {
                                "field": "Microsoft.Compute/imageSKU",
                                "like": "15*"
                              }
                            ]
                          }
                        ]
                      },
                      {
                        "allOf": [
                          {
                            "anyOf": [
                              {
                                "field": "Microsoft.Compute/imageOffer",
                                "like": "sles-12-sp*"
                              },
                              {
                                "field": "Microsoft.Compute/imageOffer",
                                "like": "sles-15-sp*"
                              },
                              {
                                "field": "Microsoft.Compute/imageOffer",
                                "like": "sles-sap-15-sp1*"
                              }
                            ]
                          },
                          {
                            "field": "Microsoft.Compute/imageSKU",
                            "in": [
                              "gen1",
                              "gen2"
                            ]
                          }
                        ]
                      }
                    ]
                  }
                ]
              },
              {
                "allOf": [
                  {
                    "field": "Microsoft.Compute/imagePublisher",
                    "equals": "Canonical"
                  },
                  {
                    "field": "Microsoft.Compute/imageOffer",
                    "in": [
                      "UbuntuServer",
                      "0001-com-ubuntu-server-focal"
                    ]
                  },
                  {
                    "anyOf": [
                      {
                        "field": "Microsoft.Compute/imageSKU",
                        "like": "14.04*LTS"
                      },
                      {
                        "field": "Microsoft.Compute/imageSKU",
                        "like": "16.04*LTS"
                      },
                      {
                        "field": "Microsoft.Compute/imageSKU",
                        "like": "16_04*lts-gen2"
                      },
                      {
                        "field": "Microsoft.Compute/imageSKU",
                        "like": "18.04*LTS"
                      },
                      {
                        "field": "Microsoft.Compute/imageSKU",
                        "like": "18_04*lts-gen2"
                      },
                      {
                        "field": "Microsoft.Compute/imageSKU",
                        "like": "20_04*lts"
                      },
                      {
                        "field": "Microsoft.Compute/imageSKU",
                        "like": "20_04*lts-gen2"
                      }
                    ]
                  }
                ]
              },
              {
                "allOf": [
                  {
                    "field": "Microsoft.Compute/imagePublisher",
                    "equals": "credativ"
                  },
                  {
                    "field": "Microsoft.Compute/imageOffer",
                    "equals": "Debian"
                  },
                  {
                    "anyOf": [
                      {
                        "field": "Microsoft.Compute/imageSKU",
                        "like": "8*"
                      },
                      {
                        "field": "Microsoft.Compute/imageSKU",
                        "like": "9*"
                      }
                    ]
                  }
                ]
              },
              {
                "allOf": [
                  {
                    "field": "Microsoft.Compute/imagePublisher",
                    "equals": "Oracle"
                  },
                  {
                    "field": "Microsoft.Compute/imageOffer",
                    "equals": "Oracle-Linux"
                  },
                  {
                    "anyOf": [
                      {
                        "field": "Microsoft.Compute/imageSKU",
                        "like": "6.*"
                      },
                      {
                        "field": "Microsoft.Compute/imageSKU",
                        "like": "7.*"
                      }
                    ]
                  }
                ]
              },
              {
                "allOf": [
                  {
                    "field": "Microsoft.Compute/imagePublisher",
                    "equals": "OpenLogic"
                  },
                  {
                    "field": "Microsoft.Compute/imageOffer",
                    "in": [
                      "CentOS",
                      "Centos-LVM",
                      "CentOS-SRIOV"
                    ]
                  },
                  {
                    "anyOf": [
                      {
                        "field": "Microsoft.Compute/imageSKU",
                        "like": "6.*"
                      },
                      {
                        "field": "Microsoft.Compute/imageSKU",
                        "like": "7*"
                      },
                      {
                        "field": "Microsoft.Compute/imageSKU",
                        "like": "8*"
                      }
                    ]
                  }
                ]
              },
              {
                "allOf": [
                  {
                    "field": "Microsoft.Compute/imagePublisher",
                    "equals": "cloudera"
                  },
                  {
                    "field": "Microsoft.Compute/imageOffer",
                    "equals": "cloudera-centos-os"
                  },
                  {
                    "field": "Microsoft.Compute/imageSKU",
                    "like": "7*"
                  }
                ]
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.Compute/virtualMachines/extensions",
          "roleDefinitionIds": [
            "/providers/microsoft.authorization/roleDefinitions/92aaf0da-9dab-42b6-94a3-d43ce8d16293"
          ],
          "existenceCondition": {
            "allOf": [
              {
                "field": "Microsoft.Compute/virtualMachines/extensions/type",
                "equals": "OmsAgentForLinux"
              },
              {
                "field": "Microsoft.Compute/virtualMachines/extensions/publisher",
                "equals": "Microsoft.EnterpriseCloud.Monitoring"
              },
              {
                "field": "Microsoft.Compute/virtualMachines/extensions/provisioningState",
                "equals": "Succeeded"
              }
            ]
          },
          "deployment": {
            "properties": {
              "mode": "incremental",
              "template": {
                "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                "contentVersion": "1.0.0.0",
                "parameters": {
                  "vmName": {
                    "type": "string"
                  },
                  "location": {
                    "type": "string"
                  },
                  "logAnalytics": {
                    "type": "string"
                  }
                },
                "variables": {
                  "vmExtensionName": "OMSAgentForLinux",
                  "vmExtensionPublisher": "Microsoft.EnterpriseCloud.Monitoring",
                  "vmExtensionType": "OmsAgentForLinux",
                  "vmExtensionTypeHandlerVersion": "1.13"
                },
                "resources": [
                  {
                    "name": "[concat(parameters('vmName'), '/', variables('vmExtensionName'))]",
                    "type": "Microsoft.Compute/virtualMachines/extensions",
                    "location": "[parameters('location')]",
                    "apiVersion": "2018-06-01",
                    "properties": {
                      "publisher": "[variables('vmExtensionPublisher')]",
                      "type": "[variables('vmExtensionType')]",
                      "typeHandlerVersion": "[variables('vmExtensionTypeHandlerVersion')]",
                      "autoUpgradeMinorVersion": true,
                      "settings": {
                        "workspaceId": "[reference(parameters('logAnalytics'), '2015-03-20').customerId]",
                        "stopOnMultipleConnections": "true"
                      },
                      "protectedSettings": {
                        "workspaceKey": "[listKeys(parameters('logAnalytics'), '2015-03-20').primarySharedKey]"
                      }
                    }
                  }
                ],
                "outputs": {
                  "policy": {
                    "type": "string",
                    "value": "[concat('Enabled extension for VM', ': ', parameters('vmName'))]"
                  }
                }
              },
              "parameters": {
                "vmName": {
                  "value": "[field('name')]"
                },
                "location": {
                  "value": "[field('location')]"
                },
                "logAnalytics": {
                  "value": "[parameters('logAnalytics')]"
                }
              }
            }
          }
        }
      }
    },
    "versions": [
      "3.1.0",
      "3.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/053d3325-282c-4e5c-b944-24faffd30d77",
  "name": "053d3325-282c-4e5c-b944-24faffd30d77"
}
Bylaw053d3325-282c-4e5c-b944-24faffd30d77.bylaw.ps1 · 145 lines
# Converted from LogAnalyticsExtension_Linux_VM_DINE.json by ConvertTo-Bylaw.
Policy '053d3325-282c-4e5c-b944-24faffd30d77' {

    Properties @{
        DisplayName   = '[Deprecated]: Deploy Log Analytics extension for Linux VMs. See deprecation notice below'
        Description   = 'This policy definition is deprecated because OMS Agent was deprecated on August 31, 2024. While there is not a specific replacement policy, we have various policies available based on the VM setup that can be found under Azure Monitor Agent/DCRA Linux. Learn more about policy definition deprecation at aka.ms/policydefdeprecation.'
        Version       = '3.1.0-deprecated'
        Category      = 'Monitoring'
        Deprecated    = $true
        PolicyVersion = '3.1.0'
        Mode          = 'Indexed'
    }

    Parameter LogAnalytics @{
        Type        = 'String'
        DisplayName = 'Log Analytics workspace'
        Description = 'Select Log Analytics workspace from dropdown list. If this workspace is outside of the scope of the assignment you must manually grant ''Log Analytics Contributor'' permissions (or similar) to the policy assignment''s principal ID.'
        Metadata    = [ordered]@{ strongType = 'omsWorkspace'; assignPermissions = $true }
    }
    Parameter ListOfImageIdToInclude @{
        Type        = 'Array'
        Default     = @()
        DisplayName = 'Optional: List of VM images that have supported Linux OS to add to scope'
        Description = 'Example value: ''/subscriptions/<subscriptionId>/resourceGroups/YourResourceGroup/providers/Microsoft.Compute/images/ContosoStdImage'''
    }
    Parameter Effect @{
        AllowedValues = @('DeployIfNotExists', 'Disabled')
        Default       = 'Disabled'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy.'
    }

    Resource 'Microsoft.Compute/virtualMachines' {

        Require 'imageId is not one of the ListOfImageIdToInclude parameter' {
            Field 'Microsoft.Compute/imageId' | Must -Not -BeIn (Param ListOfImageIdToInclude) -IfPresent
        }

        Require 'imagePublisher, imageOffer and imageSKU are as required' {
            AnyOf {
                Field 'Microsoft.Compute/imagePublisher' | Must -Not -Be 'RedHat' -IfPresent
                Field 'Microsoft.Compute/imageOffer' | Must -Not -BeIn @('RHEL', 'RHEL-SAP-HANA') -IfPresent
                AllOf {
                    Field 'Microsoft.Compute/imageSKU' | Must -Not -BeLike '6.*' -IfPresent
                    Field 'Microsoft.Compute/imageSKU' | Must -Not -BeLike '7*' -IfPresent
                    Field 'Microsoft.Compute/imageSKU' | Must -Not -BeLike '8*' -IfPresent
                }
            }
        }

        Require 'imagePublisher, imageOffer and imageSKU are as required' {
            AnyOf {
                Field 'Microsoft.Compute/imagePublisher' | Must -Not -Be 'SUSE' -IfPresent
                AllOf {
                    AnyOf {
                        Field 'Microsoft.Compute/imageOffer' | Must -Not -BeIn @('SLES', 'SLES-HPC', 'SLES-HPC-Priority', 'SLES-SAP', 'SLES-SAP-BYOS', 'SLES-Priority', 'SLES-BYOS', 'SLES-SAPCAL', 'SLES-Standard') -IfPresent
                        AllOf {
                            Field 'Microsoft.Compute/imageSKU' | Must -Not -BeLike '12*' -IfPresent
                            Field 'Microsoft.Compute/imageSKU' | Must -Not -BeLike '15*' -IfPresent
                        }
                    }
                    AnyOf {
                        AllOf {
                            Field 'Microsoft.Compute/imageOffer' | Must -Not -BeLike 'sles-12-sp*' -IfPresent
                            Field 'Microsoft.Compute/imageOffer' | Must -Not -BeLike 'sles-15-sp*' -IfPresent
                            Field 'Microsoft.Compute/imageOffer' | Must -Not -BeLike 'sles-sap-15-sp1*' -IfPresent
                        }
                        Field 'Microsoft.Compute/imageSKU' | Must -Not -BeIn @('gen1', 'gen2') -IfPresent
                    }
                }
            }
        }

        Require 'imagePublisher, imageOffer and imageSKU are as required' {
            AnyOf {
                Field 'Microsoft.Compute/imagePublisher' | Must -Not -Be 'Canonical' -IfPresent
                Field 'Microsoft.Compute/imageOffer' | Must -Not -BeIn @('UbuntuServer', '0001-com-ubuntu-server-focal') -IfPresent
                AllOf {
                    Field 'Microsoft.Compute/imageSKU' | Must -Not -BeLike '14.04*LTS' -IfPresent
                    Field 'Microsoft.Compute/imageSKU' | Must -Not -BeLike '16.04*LTS' -IfPresent
                    Field 'Microsoft.Compute/imageSKU' | Must -Not -BeLike '16_04*lts-gen2' -IfPresent
                    Field 'Microsoft.Compute/imageSKU' | Must -Not -BeLike '18.04*LTS' -IfPresent
                    Field 'Microsoft.Compute/imageSKU' | Must -Not -BeLike '18_04*lts-gen2' -IfPresent
                    Field 'Microsoft.Compute/imageSKU' | Must -Not -BeLike '20_04*lts' -IfPresent
                    Field 'Microsoft.Compute/imageSKU' | Must -Not -BeLike '20_04*lts-gen2' -IfPresent
                }
            }
        }

        Require 'imagePublisher, imageOffer and imageSKU are as required' {
            AnyOf {
                Field 'Microsoft.Compute/imagePublisher' | Must -Not -Be 'credativ' -IfPresent
                Field 'Microsoft.Compute/imageOffer' | Must -Not -Be 'Debian' -IfPresent
                AllOf {
                    Field 'Microsoft.Compute/imageSKU' | Must -Not -BeLike '8*' -IfPresent
                    Field 'Microsoft.Compute/imageSKU' | Must -Not -BeLike '9*' -IfPresent
                }
            }
        }

        Require 'imagePublisher, imageOffer and imageSKU are as required' {
            AnyOf {
                Field 'Microsoft.Compute/imagePublisher' | Must -Not -Be 'Oracle' -IfPresent
                Field 'Microsoft.Compute/imageOffer' | Must -Not -Be 'Oracle-Linux' -IfPresent
                AllOf {
                    Field 'Microsoft.Compute/imageSKU' | Must -Not -BeLike '6.*' -IfPresent
                    Field 'Microsoft.Compute/imageSKU' | Must -Not -BeLike '7.*' -IfPresent
                }
            }
        }

        Require 'imagePublisher, imageOffer and imageSKU are as required' {
            AnyOf {
                Field 'Microsoft.Compute/imagePublisher' | Must -Not -Be 'OpenLogic' -IfPresent
                Field 'Microsoft.Compute/imageOffer' | Must -Not -BeIn @('CentOS', 'Centos-LVM', 'CentOS-SRIOV') -IfPresent
                AllOf {
                    Field 'Microsoft.Compute/imageSKU' | Must -Not -BeLike '6.*' -IfPresent
                    Field 'Microsoft.Compute/imageSKU' | Must -Not -BeLike '7*' -IfPresent
                    Field 'Microsoft.Compute/imageSKU' | Must -Not -BeLike '8*' -IfPresent
                }
            }
        }

        Require 'imagePublisher, imageOffer and imageSKU are as required' {
            AnyOf {
                Field 'Microsoft.Compute/imagePublisher' | Must -Not -Be 'cloudera' -IfPresent
                Field 'Microsoft.Compute/imageOffer' | Must -Not -Be 'cloudera-centos-os' -IfPresent
                Field 'Microsoft.Compute/imageSKU' | Must -Not -BeLike '7*' -IfPresent
            }
        }
    }

    DeployIfNotExists 'Microsoft.Compute/virtualMachines/extensions' -Role 'Log Analytics Contributor' -Effect (Param Effect) {
        Require 'type, publisher and provisioningState are as required' {
            Field 'Microsoft.Compute/virtualMachines/extensions/type' | Must -Be 'OmsAgentForLinux'
            Field publisher | Must -Be 'Microsoft.EnterpriseCloud.Monitoring'
            Field provisioningState | Must -Be 'Succeeded'
        }
        Deployment -TemplateFile './templates/053d3325-282c-4e5c-b944-24faffd30d77.json' -Parameters ([ordered]@{
                vmName       = (Arm '[field(''name'')]')
                location     = (Arm '[field(''location'')]')
                logAnalytics = (Param LogAnalytics)
            })
    }
}

Its deployment templates are written beside it:

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