Gallery › Network › Azure built-in policies
Create central Log Analytics Workspace for VNet Flowlog Traffic Analytics in the specified Resource Group
Converted Policy DeployIfNotExists Disabled Mode All Version 1.0.0
Create a central Log Analytics Workspace in the assigned Scope and under Resource Group nwtarg-<subscriptionID> by default for VNet flowlogs.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONVirtualNetwork_Flowlog_TrafficAnalytics_LogAnalytics_DINE.json · 165 lines
{
"properties": {
"displayName": "Create central Log Analytics Workspace for VNet Flowlog Traffic Analytics in the specified Resource Group",
"description": "Create a central Log Analytics Workspace in the assigned Scope and under Resource Group nwtarg-<subscriptionID> by default for VNet flowlogs.",
"policyType": "BuiltIn",
"mode": "All",
"metadata": {
"version": "1.0.0",
"category": "Network"
},
"version": "1.0.0",
"parameters": {
"effect": {
"type": "String",
"allowedValues": [
"DeployIfNotExists",
"Disabled"
],
"defaultValue": "DeployIfNotExists",
"metadata": {
"displayName": "Effect",
"description": "Enable or disable the execution of the policy"
}
},
"resourceGroupName": {
"type": "String",
"metadata": {
"displayName": "Resource Group",
"description": "Resource Group in which the Log Analytics Workspace 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."
},
"defaultValue": "nwtarg"
},
"workspaceRegion": {
"type": "String",
"metadata": {
"displayName": "Workspace Region",
"description": "Region where the workspace will be deployed",
"strongType": "location"
},
"defaultValue": "eastus"
}
},
"policyRule": {
"if": {
"field": "type",
"equals": "Microsoft.Resources/subscriptions"
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.OperationalInsights/workspaces",
"name": "[toLower(concat('nwtaws', uniqueString(concat(subscription().subscriptionId, parameters('workspaceRegion')))))]",
"ResourceGroupName": "[parameters('resourceGroupName')]",
"existenceScope": "resourceGroup",
"deploymentScope": "Subscription",
"existenceCondition": {
"allOf": [
{
"field": "id",
"equals": "[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', if(equals(parameters('resourceGroupName'), 'nwtarg'), concat('nwtarg-', subscription().subscriptionId), parameters('resourceGroupName')), '/providers/Microsoft.OperationalInsights/workspaces/', toLower(concat('nwtaws', uniqueString(concat(subscription().subscriptionId, parameters('workspaceRegion'))))))]"
},
{
"field": "location",
"equals": "[parameters('workspaceRegion')]"
}
]
},
"roleDefinitionIds": [
"/providers/microsoft.authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
],
"deployment": {
"location": "eastus",
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-08-01/subscriptionDeploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"workspaceRegion": {
"type": "String"
},
"resourceGroupName": {
"type": "String"
}
},
"variables": {
"workspaceName": "[toLower(concat('nwtaws', uniqueString(concat(subscription().subscriptionId, parameters('workspaceRegion')))))]",
"resourceGroupNameResolved": "[if(equals(parameters('resourceGroupName'), 'nwtarg'), concat('nwtarg-', subscription().subscriptionId), parameters('resourceGroupName'))]"
},
"resources": [
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2021-04-01",
"name": "[concat('deploynwtarg-', uniqueString(subscription().subscriptionId, parameters('workspaceRegion')))]",
"location": "eastus",
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.Resources/resourceGroups",
"apiVersion": "2021-04-01",
"name": "[variables('resourceGroupNameResolved')]",
"location": "eastus"
}
]
}
}
},
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2021-04-01",
"name": "[concat('deployWorkspaceForFlowlog-', uniqueString(subscription().subscriptionId, parameters('workspaceRegion')))]",
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"variables": {
"workspaceName": "[toLower(concat('nwtaws', uniqueString(concat(subscription().subscriptionId, parameters('workspaceRegion')))))]"
},
"resources": [
{
"type": "Microsoft.OperationalInsights/workspaces",
"apiVersion": "2021-06-01",
"name": "[variables('workspaceName')]",
"location": "[parameters('workspaceRegion')]",
"properties": {
"sku": {
"name": "PerGB2018"
}
}
}
]
}
},
"resourceGroup": "[variables('resourceGroupNameResolved')]",
"dependsOn": [
"[concat('deploynwtarg-', uniqueString(subscription().subscriptionId, parameters('workspaceRegion')))]"
]
}
]
},
"parameters": {
"workspaceRegion": {
"value": "[parameters('workspaceRegion')]"
},
"resourceGroupName": {
"value": "[parameters('resourceGroupName')]"
}
}
}
}
}
}
},
"versions": [
"1.0.0"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/69f5d115-d282-4c1b-9c76-7f6640427d2e",
"name": "69f5d115-d282-4c1b-9c76-7f6640427d2e"
}Bylaw69f5d115-d282-4c1b-9c76-7f6640427d2e.bylaw.ps1 · 48 lines
# Converted from VirtualNetwork_Flowlog_TrafficAnalytics_LogAnalytics_DINE.json by ConvertTo-Bylaw.
Policy '69f5d115-d282-4c1b-9c76-7f6640427d2e' {
Properties @{
DisplayName = 'Create central Log Analytics Workspace for VNet Flowlog Traffic Analytics in the specified Resource Group'
Description = 'Create a central Log Analytics Workspace in the assigned Scope and under Resource Group nwtarg-<subscriptionID> by default for VNet flowlogs.'
Version = '1.0.0'
Category = 'Network'
PolicyVersion = '1.0.0'
Mode = 'All'
}
Parameter Effect @{
AllowedValues = @('DeployIfNotExists', 'Disabled')
Default = 'DeployIfNotExists'
DisplayName = 'Effect'
Description = 'Enable or disable the execution of the policy'
}
Parameter ResourceGroupName @{
Default = 'nwtarg'
DisplayName = 'Resource Group'
Description = 'Resource Group in which the Log Analytics Workspace 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 WorkspaceRegion @{
Default = 'eastus'
DisplayName = 'Workspace Region'
Description = 'Region where the workspace will be deployed'
Metadata = [ordered]@{ strongType = 'location' }
}
Resource 'Microsoft.Resources/subscriptions'
DeployIfNotExists 'Microsoft.OperationalInsights/workspaces' -Role 'Contributor' -Name (Arm '[toLower(concat(''nwtaws'', uniqueString(concat(subscription().subscriptionId, parameters(''workspaceRegion'')))))]') -ResourceGroupName (Param ResourceGroupName) -ExistenceScope ResourceGroup -Effect (Param Effect) {
Require 'id and location are as required' {
Field id | Must -Be (Arm '[concat(''/subscriptions/'', subscription().subscriptionId, ''/resourceGroups/'', if(equals(parameters(''resourceGroupName''), ''nwtarg''), concat(''nwtarg-'', subscription().subscriptionId), parameters(''resourceGroupName'')), ''/providers/Microsoft.OperationalInsights/workspaces/'', toLower(concat(''nwtaws'', uniqueString(concat(subscription().subscriptionId, parameters(''workspaceRegion''))))))]')
Field location | Must -Be (Param WorkspaceRegion)
}
Deployment @{
TemplateFile = './templates/69f5d115-d282-4c1b-9c76-7f6640427d2e.json'
Scope = 'Subscription'
Location = 'eastus'
Parameters = [ordered]@{
workspaceRegion = (Param WorkspaceRegion)
resourceGroupName = (Param ResourceGroupName)
}
}
}
}Its deployment templates are written beside it:
templates/69f5d115-d282-4c1b-9c76-7f6640427d2e.json
Source: built-in-policies/policyDefinitions/Network/VirtualNetwork_Flowlog_TrafficAnalytics_LogAnalytics_DINE.json in Azure/azure-policy, under the MIT licence.
Bylaw