Bylaw

Gallery › Network › Azure built-in policies

Enable VNet Flowlog and Traffic Analytics with regional Storage and centralized Log Analytics

Converted Initiative Version 1.0.0

This policy set enables VNet Flowlog and Traffic Analytics by creating a regional Storage Account, a Log Analytics Workspace in a centrally managed region, and creates a Network Watcher Resource if needed in the Region.

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

Azure Policy JSONVirtualNetwork_Flowlog_TrafficAnalytics.json · 137 lines
{
  "properties": {
    "displayName": "Enable VNet Flowlog and Traffic Analytics with regional Storage and centralized Log Analytics",
    "description": "This policy set enables VNet Flowlog and Traffic Analytics by creating a regional Storage Account, a Log Analytics Workspace in a centrally managed region, and creates a Network Watcher Resource if needed in the Region.",
    "policyType": "BuiltIn",
    "metadata": {
      "version": "1.0.0",
      "category": "Network"
    },
    "version": "1.0.0",
    "parameters": {
      "location": {
        "type": "string",
        "metadata": {
          "description": "The location where the Resource Group, Storage Account, Network Watcher and lowlog will be created if already does not exist",
          "displayName": "Location",
          "portalReview": true,
          "strongType": "location"
        }
      },
      "resourceGroupName": {
        "type": "string",
        "metadata": {
          "description": "Resource Group in which Storage Sccount for VNet Flowlogs exists or will be created in. By default will be nwtarg-<subscriptionId>, if needs to be customized, please update to a value other than nwtarg.",
          "displayName": "Resource Group Name"
        },
        "defaultValue": "nwtarg"
      },
      "retentionDays": {
        "type": "string",
        "metadata": {
          "description": "The number of days for which Flowlog data will be retained in Storage Account. If you want to retain data forever and do not want to apply any retention policy, set retention (days) to 0.",
          "displayName": "Number of days to retain flow logs"
        },
        "defaultValue": "0"
      },
      "timeIntervalInMin": {
        "type": "string",
        "metadata": {
          "description": "Traffic analytics processes blobs at the selected frequency. Default is 60 minutes.",
          "displayName": "Time Interval In Mins"
        },
        "allowedValues": [
          "10",
          "60"
        ],
        "defaultValue": "60"
      },
      "workspaceRegion": {
        "type": "string",
        "metadata": {
          "description": "Region to create the Log Analytics Workspace.",
          "displayName": "Workspace Region",
          "strongType": "location"
        },
        "defaultValue": "eastus"
      },
      "updateFlowlog": {
        "type": "string",
        "metadata": {
          "description": "Set to \"True\" by default. When enabled, existing VNet Flowlogs will be updated to push data to the newly created regional storage account and Log Analytics workspace. Set to \"False\" to skip updating existing Flowlogs.",
          "displayName": "Update existing Flowlogs with regional Storage and Workspace"
        },
        "allowedValues": [
          "True",
          "False"
        ],
        "defaultValue": "True"
      }
    },
    "policyDefinitions": [
      {
        "policyDefinitionReferenceId": "Deploy VNet Flowlogs with Traffic Analytics for VNets with regional Storage and centralized Log Analytics",
        "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/6d7c9ba4-b4b9-4d38-9e86-f1bc6b322bde",
        "definitionVersion": "1.*.*",
        "parameters": {
          "resourceGroupName": {
            "value": "[parameters('resourceGroupName')]"
          },
          "workspaceRegion": {
            "value": "[parameters('workspaceRegion')]"
          },
          "timeIntervalInMins": {
            "value": "[parameters('timeIntervalInMin')]"
          },
          "updateFlowlog": {
            "value": "[parameters('updateFlowlog')]"
          },
          "retentionDays": {
            "value": "[parameters('retentionDays')]"
          }
        }
      },
      {
        "policyDefinitionReferenceId": "Create regional Storage Account for VNet Flowlogs in resourceGroupName RG",
        "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/1c46fa74-ad5c-46e4-9cf3-6bf88e3adcba",
        "definitionVersion": "1.*.*",
        "parameters": {
          "resourceGroupName": {
            "value": "[parameters('resourceGroupName')]"
          },
          "location": {
            "value": "[parameters('location')]"
          }
        }
      },
      {
        "policyDefinitionReferenceId": "Create central Log Analytics Workspace for VNet Flowlog Traffic Analytics in the specified Resource Group",
        "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/69f5d115-d282-4c1b-9c76-7f6640427d2e",
        "definitionVersion": "1.*.*",
        "parameters": {
          "resourceGroupName": {
            "value": "[parameters('resourceGroupName')]"
          },
          "workspaceRegion": {
            "value": "[parameters('workspaceRegion')]"
          }
        }
      },
      {
        "policyDefinitionReferenceId": "Create Regional NetworkWatcher in NetworkWatcherRG for VNet flowlogs",
        "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/6f4374d1-455b-4f14-83d9-3bf5133c5bb5",
        "definitionVersion": "1.*.*",
        "parameters": {
          "location": {
            "value": "[parameters('location')]"
          }
        }
      }
    ],
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policySetDefinitions/55634457-45e5-473f-b5c5-55cef2b20b52",
  "name": "55634457-45e5-473f-b5c5-55cef2b20b52"
}
Bylaw55634457-45e5-473f-b5c5-55cef2b20b52.bylaw.ps1 · 93 lines
# Converted from VirtualNetwork_Flowlog_TrafficAnalytics.json by ConvertTo-Bylaw.
Initiative '55634457-45e5-473f-b5c5-55cef2b20b52' {

    Properties @{
        DisplayName   = 'Enable VNet Flowlog and Traffic Analytics with regional Storage and centralized Log Analytics'
        Description   = 'This policy set enables VNet Flowlog and Traffic Analytics by creating a regional Storage Account, a Log Analytics Workspace in a centrally managed region, and creates a Network Watcher Resource if needed in the Region.'
        Version       = '1.0.0'
        Category      = 'Network'
        PolicyVersion = '1.0.0'
    }

    Parameter Location @{
        Type        = 'string'
        DisplayName = 'Location'
        Description = 'The location where the Resource Group, Storage Account, Network Watcher and lowlog will be created if already does not exist'
        Metadata    = [ordered]@{ portalReview = $true; strongType = 'location' }
    }
    Parameter ResourceGroupName @{
        Type        = 'string'
        Default     = 'nwtarg'
        DisplayName = 'Resource Group Name'
        Description = 'Resource Group in which Storage Sccount for VNet Flowlogs exists or will be created in. By default will be nwtarg-<subscriptionId>, if needs to be customized, please update to a value other than nwtarg.'
    }
    Parameter RetentionDays @{
        Type        = 'string'
        Default     = '0'
        DisplayName = 'Number of days to retain flow logs'
        Description = 'The number of days for which Flowlog data will be retained in Storage Account. If you want to retain data forever and do not want to apply any retention policy, set retention (days) to 0.'
    }
    Parameter TimeIntervalInMin @{
        Type          = 'string'
        AllowedValues = @('10', '60')
        Default       = '60'
        DisplayName   = 'Time Interval In Mins'
        Description   = 'Traffic analytics processes blobs at the selected frequency. Default is 60 minutes.'
    }
    Parameter WorkspaceRegion @{
        Type        = 'string'
        Default     = 'eastus'
        DisplayName = 'Workspace Region'
        Description = 'Region to create the Log Analytics Workspace.'
        Metadata    = [ordered]@{ strongType = 'location' }
    }
    Parameter UpdateFlowlog @{
        Type          = 'string'
        AllowedValues = @('True', 'False')
        Default       = 'True'
        DisplayName   = 'Update existing Flowlogs with regional Storage and Workspace'
        Description   = 'Set to "True" by default. When enabled, existing VNet Flowlogs will be updated to push data to the newly created regional storage account and Log Analytics workspace. Set to "False" to skip updating existing Flowlogs.'
    }

    PolicyDefinition @{
        Id          = '6d7c9ba4-b4b9-4d38-9e86-f1bc6b322bde'
        ReferenceId = 'Deploy VNet Flowlogs with Traffic Analytics for VNets with regional Storage and centralized Log Analytics'
        Version     = '1.*.*'
        Parameters  = [ordered]@{
            resourceGroupName  = (Param ResourceGroupName)
            workspaceRegion    = (Param WorkspaceRegion)
            timeIntervalInMins = (Param TimeIntervalInMin)
            updateFlowlog      = (Param UpdateFlowlog)
            retentionDays      = (Param RetentionDays)
        }
    }

    PolicyDefinition @{
        Id          = '1c46fa74-ad5c-46e4-9cf3-6bf88e3adcba'
        ReferenceId = 'Create regional Storage Account for VNet Flowlogs in resourceGroupName RG'
        Version     = '1.*.*'
        Parameters  = [ordered]@{
            resourceGroupName = (Param ResourceGroupName)
            location          = (Param Location)
        }
    }

    PolicyDefinition @{
        Id          = '69f5d115-d282-4c1b-9c76-7f6640427d2e'
        ReferenceId = 'Create central Log Analytics Workspace for VNet Flowlog Traffic Analytics in the specified Resource Group'
        Version     = '1.*.*'
        Parameters  = [ordered]@{
            resourceGroupName = (Param ResourceGroupName)
            workspaceRegion   = (Param WorkspaceRegion)
        }
    }

    PolicyDefinition @{
        Id          = '6f4374d1-455b-4f14-83d9-3bf5133c5bb5'
        ReferenceId = 'Create Regional NetworkWatcher in NetworkWatcherRG for VNet flowlogs'
        Version     = '1.*.*'
        Parameters  = @{
            location = (Param Location)
        }
    }
}

Members (4)

Source: built-in-policies/policySetDefinitions/Network/VirtualNetwork_Flowlog_TrafficAnalytics.json in Azure/azure-policy, under the MIT licence.