Skip to content

Instantly share code, notes, and snippets.

@krnese
Created December 6, 2018 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krnese/72120ee1f31940a3449dd27d2da0773f to your computer and use it in GitHub Desktop.
Save krnese/72120ee1f31940a3449dd27d2da0773f to your computer and use it in GitHub Desktop.
{
"properties": {
"policyType": "Custom",
"mode": "All",
"parameters": {
"logAnalyticsEurope": {
"type": "string",
"metadata": {
"displayName": "Log Analyitcs workspace in Europe",
"description": "Select the Log Analytics workspace from dropdown list",
"strongType": "omsWorkspace"
}
},
"logAnalyticsAmerica": {
"type": "string",
"metadata": {
"displayName": "Log Analytics workspace in America",
"description": "Select the Log Analytics workspace from dropdown list",
"strongType": "omsWorkspace"
}
}
},
"policyRule": {
"if": {
"field": "type",
"equals": "Microsoft.Network/networkSecurityGroups"
},
"then": {
"effect": "deployIfNotExists",
"details": {
"type": "Microsoft.Insights/diagnosticSettings",
"name": "setByPolicy",
"existenceCondition": {
"allOf": [
{
"field": "Microsoft.Insights/diagnosticSettings/logs.enabled",
"equals": "true"
},
{
"field": "Microsoft.Insights/diagnosticSettings/workspaceId",
"in": [
"[parameters('logAnalyticsEurope')]",
"[parameters('logAnalyticsAmerica')]"
]
}
]
},
"deployment": {
"properties": {
"parameters": {
"logAnalyticsEurope": {
"value": "[parameters('logAnalyticsEurope')]"
},
"logAnalyticsAmerica": {
"value": "[parameters('logAnalyticsAmerica')]"
},
"location": {
"value": "[field('location')]"
},
"nsgName": {
"value": "[field('name')]"
}
},
"mode": "incremental",
"template": {
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"nsgName": {
"type": "string"
},
"logAnalyticsEurope": {
"type": "string"
},
"logAnalyticsAmerica": {
"type": "string"
},
"location": {
"type": "string"
}
},
"variables": {},
"resources": [
{
"condition": "[equals(parameters('location'), 'northeurope')]",
"type": "Microsoft.Network/networkSecurityGroups/providers/diagnosticSettings",
"apiVersion": "2017-05-01-preview",
"name": "[concat(parameters('nsgName'), '/', 'Microsoft.Insights/setByPolicyEU')]",
"location": "[parameters('location')]",
"dependsOn": [],
"properties": {
"workspaceId": "[parameters('logAnalyticsEurope')]",
"logs": [
{
"category": "NetworkSecurityGroupEvent",
"enabled": true
},
{
"category": "NetworkSecurityGroupRuleCounter",
"enabled": true
}
]
}
},
{
"condition": "[equals(parameters('location'), 'eastus')]",
"type": "Microsoft.Network/networkSecurityGroups/providers/diagnosticSettings",
"apiVersion": "2017-05-01-preview",
"name": "[concat(parameters('nsgName'), '/', 'Microsoft.Insights/setByPolicyUS')]",
"location": "[parameters('location')]",
"dependsOn": [],
"properties": {
"workspaceId": "[parameters('logAnalyticsAmerica')]",
"logs": [
{
"category": "NetworkSecurityGroupEvent",
"enabled": true
},
{
"category": "NetworkSecurityGroupRuleCounter",
"enabled": true
}
]
}
}
],
"outputs": {}
}
}
},
"roleDefinitionIds": [
"/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
]
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment