Bylaw

Gallery › Monitoring › Azure Landing Zones Library

[Deprecated]: Deploy Diagnostic Settings for VWAN S2S VPN Gateway to Log Analytics workspace

Converted Policy DeployIfNotExists Disabled Mode Indexed Version 1.0.0-deprecated Deprecated

Deploys the diagnostic settings for VWAN S2S VPN Gateway to stream to a Log Analytics workspace when any VWAN S2S VPN Gateway which is missing this diagnostic settings is created or updated. This policy is superseded by built-in initiative https://www.azadvertizer.net/azpolicyinitiativesadvertizer/0884adba-2312-4468-abeb-5422caed1038.html.

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

Azure Policy JSONDeploy-Diagnostics-VWanS2SVPNGW.alz_policy_definition.json · 200 lines
{
  "name": "Deploy-Diagnostics-VWanS2SVPNGW",
  "properties": {
    "description": "Deploys the diagnostic settings for VWAN S2S VPN Gateway to stream to a Log Analytics workspace when any VWAN S2S VPN Gateway which is missing this diagnostic settings is created or updated. This policy is superseded by built-in initiative https://www.azadvertizer.net/azpolicyinitiativesadvertizer/0884adba-2312-4468-abeb-5422caed1038.html.",
    "displayName": "[Deprecated]: Deploy Diagnostic Settings for VWAN S2S VPN Gateway to Log Analytics workspace",
    "metadata": {
      "alzCloudEnvironments": [
        "AzureCloud",
        "AzureChinaCloud",
        "AzureUSGovernment"
      ],
      "category": "Monitoring",
      "deprecated": true,
      "source": "https://github.com/Azure/Enterprise-Scale/",
      "version": "1.0.0-deprecated"
    },
    "mode": "Indexed",
    "parameters": {
      "effect": {
        "allowedValues": [
          "DeployIfNotExists",
          "Disabled"
        ],
        "defaultValue": "DeployIfNotExists",
        "metadata": {
          "description": "Enable or disable the execution of the policy",
          "displayName": "Effect"
        },
        "type": "String"
      },
      "logAnalytics": {
        "metadata": {
          "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.",
          "displayName": "Log Analytics workspace",
          "strongType": "omsWorkspace"
        },
        "type": "String"
      },
      "logsEnabled": {
        "allowedValues": [
          "True",
          "False"
        ],
        "defaultValue": "True",
        "metadata": {
          "description": "Whether to enable logs stream to the Log Analytics workspace - True or False",
          "displayName": "Enable logs"
        },
        "type": "String"
      },
      "metricsEnabled": {
        "allowedValues": [
          "True",
          "False"
        ],
        "defaultValue": "True",
        "metadata": {
          "description": "Whether to enable metrics stream to the Log Analytics workspace - True or False",
          "displayName": "Enable metrics"
        },
        "type": "String"
      },
      "profileName": {
        "defaultValue": "setbypolicy",
        "metadata": {
          "description": "The diagnostic settings profile name",
          "displayName": "Profile name"
        },
        "type": "String"
      }
    },
    "policyRule": {
      "if": {
        "equals": "Microsoft.Network/vpnGateways",
        "field": "type"
      },
      "then": {
        "details": {
          "deployment": {
            "properties": {
              "mode": "Incremental",
              "parameters": {
                "location": {
                  "value": "[field('location')]"
                },
                "logAnalytics": {
                  "value": "[parameters('logAnalytics')]"
                },
                "logsEnabled": {
                  "value": "[parameters('logsEnabled')]"
                },
                "metricsEnabled": {
                  "value": "[parameters('metricsEnabled')]"
                },
                "profileName": {
                  "value": "[parameters('profileName')]"
                },
                "resourceName": {
                  "value": "[field('name')]"
                }
              },
              "template": {
                "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                "contentVersion": "1.0.0.0",
                "outputs": {},
                "parameters": {
                  "location": {
                    "type": "String"
                  },
                  "logAnalytics": {
                    "type": "String"
                  },
                  "logsEnabled": {
                    "type": "String"
                  },
                  "metricsEnabled": {
                    "type": "String"
                  },
                  "profileName": {
                    "type": "String"
                  },
                  "resourceName": {
                    "type": "String"
                  }
                },
                "resources": [
                  {
                    "apiVersion": "2017-05-01-preview",
                    "dependsOn": [],
                    "location": "[parameters('location')]",
                    "name": "[concat(parameters('resourceName'), '/', 'Microsoft.Insights/', parameters('profileName'))]",
                    "properties": {
                      "logs": [
                        {
                          "category": "GatewayDiagnosticLog",
                          "enabled": "[parameters('logsEnabled')]"
                        },
                        {
                          "category": "IKEDiagnosticLog",
                          "enabled": "[parameters('logsEnabled')]"
                        },
                        {
                          "category": "RouteDiagnosticLog",
                          "enabled": "[parameters('logsEnabled')]"
                        },
                        {
                          "category": "TunnelDiagnosticLog",
                          "enabled": "[parameters('logsEnabled')]"
                        }
                      ],
                      "metrics": [
                        {
                          "category": "AllMetrics",
                          "enabled": "[parameters('metricsEnabled')]",
                          "retentionPolicy": {
                            "days": 0,
                            "enabled": false
                          },
                          "timeGrain": null
                        }
                      ],
                      "workspaceId": "[parameters('logAnalytics')]"
                    },
                    "type": "Microsoft.Network/vpnGateways/providers/diagnosticSettings"
                  }
                ],
                "variables": {}
              }
            }
          },
          "existenceCondition": {
            "allOf": [
              {
                "equals": "true",
                "field": "Microsoft.Insights/diagnosticSettings/logs.enabled"
              },
              {
                "equals": "true",
                "field": "Microsoft.Insights/diagnosticSettings/metrics.enabled"
              },
              {
                "equals": "[parameters('logAnalytics')]",
                "field": "Microsoft.Insights/diagnosticSettings/workspaceId"
              }
            ]
          },
          "name": "[parameters('profileName')]",
          "roleDefinitionIds": [
            "/providers/microsoft.authorization/roleDefinitions/749f88d5-cbae-40b8-bcfc-e573ddc772fa",
            "/providers/microsoft.authorization/roleDefinitions/92aaf0da-9dab-42b6-94a3-d43ce8d16293"
          ],
          "type": "Microsoft.Insights/diagnosticSettings"
        },
        "effect": "[parameters('effect')]"
      }
    },
    "policyType": "Custom"
  },
  "type": "Microsoft.Authorization/policyDefinitions"
}
BylawDeploy-Diagnostics-VWanS2SVPNGW.bylaw.ps1 · 61 lines
# Converted from Deploy-Diagnostics-VWanS2SVPNGW.alz_policy_definition.json by ConvertTo-Bylaw.
Policy 'Deploy-Diagnostics-VWanS2SVPNGW' {

    Properties @{
        DisplayName = '[Deprecated]: Deploy Diagnostic Settings for VWAN S2S VPN Gateway to Log Analytics workspace'
        Description = 'Deploys the diagnostic settings for VWAN S2S VPN Gateway to stream to a Log Analytics workspace when any VWAN S2S VPN Gateway which is missing this diagnostic settings is created or updated. This policy is superseded by built-in initiative https://www.azadvertizer.net/azpolicyinitiativesadvertizer/0884adba-2312-4468-abeb-5422caed1038.html.'
        Category    = 'Monitoring'
        Deprecated  = $true
        Version     = '1.0.0-deprecated'
        Mode        = 'Indexed'
        Metadata    = [ordered]@{ alzCloudEnvironments = @('AzureCloud', 'AzureChinaCloud', 'AzureUSGovernment'); source = 'https://github.com/Azure/Enterprise-Scale/' }
    }

    Parameter Effect @{
        AllowedValues = @('DeployIfNotExists', 'Disabled')
        Default       = 'DeployIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }
    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' }
    }
    Parameter LogsEnabled @{
        AllowedValues = @('True', 'False')
        Default       = 'True'
        DisplayName   = 'Enable logs'
        Description   = 'Whether to enable logs stream to the Log Analytics workspace - True or False'
    }
    Parameter MetricsEnabled @{
        AllowedValues = @('True', 'False')
        Default       = 'True'
        DisplayName   = 'Enable metrics'
        Description   = 'Whether to enable metrics stream to the Log Analytics workspace - True or False'
    }
    Parameter ProfileName @{
        Default     = 'setbypolicy'
        DisplayName = 'Profile name'
        Description = 'The diagnostic settings profile name'
    }

    Resource 'Microsoft.Network/vpnGateways'

    DeployIfNotExists 'Microsoft.Insights/diagnosticSettings' -Role 'Monitoring Contributor', 'Log Analytics Contributor' -Name (Param ProfileName) -Effect (Param Effect) {
        Require 'logs.enabled is true, metrics.enabled is true and workspaceId is the LogAnalytics parameter' {
            Field logs.enabled | Must -Be 'true'
            Field metrics.enabled | Must -Be 'true'
            Field workspaceId | Must -Be (Param LogAnalytics)
        }
        Deployment -TemplateFile './templates/Deploy-Diagnostics-VWanS2SVPNGW.json' -Parameters ([ordered]@{
                location       = (Arm '[field(''location'')]')
                logAnalytics   = (Param LogAnalytics)
                logsEnabled    = (Param LogsEnabled)
                metricsEnabled = (Param MetricsEnabled)
                profileName    = (Param ProfileName)
                resourceName   = (Arm '[field(''name'')]')
            })
    }
}

Its deployment templates are written beside it:

Source: policy_definitions/Deploy-Diagnostics-VWanS2SVPNGW.alz_policy_definition.json in Azure/Azure-Landing-Zones-Library, under the MIT licence.