Gallery › Network › Azure built-in policies
Create regional Storage Account for VNet Flowlogs in resourceGroupName RG
Converted Policy DeployIfNotExists Disabled Mode All Version 1.0.0
Creates a regional Storage Account 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_StorageAccount_DINE.json · 165 lines
{
"properties": {
"displayName": "Create regional Storage Account for VNet Flowlogs in resourceGroupName RG",
"description": "Creates a regional Storage Account 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 storage account 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"
},
"location": {
"type": "String",
"metadata": {
"displayName": "Storage Account Location",
"description": "Location where the Storage Account exists or will be created in. It should match the location of the Virtual Network where flowlog is to be enabled.",
"strongType": "location"
}
}
},
"policyRule": {
"if": {
"field": "type",
"equals": "Microsoft.Resources/subscriptions"
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.Storage/storageAccounts",
"name": "[toLower(concat('nwtasa', uniqueString(concat(subscription().subscriptionId, parameters('location')))))]",
"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.Storage/storageAccounts/', toLower(concat('nwtasa', uniqueString(concat(subscription().subscriptionId, parameters('location'))))))]"
},
{
"field": "location",
"equals": "[parameters('location')]"
}
]
},
"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": {
"location": {
"type": "String"
},
"resourceGroupName": {
"type": "String"
}
},
"variables": {
"storageAccountName": "[toLower(concat('nwtasa', uniqueString(concat(subscription().subscriptionId, parameters('location')))))]",
"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('location')))]",
"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('deployStorageForFlowlog', uniqueString(concat(subscription().subscriptionId, parameters('location'))))]",
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2023-01-01",
"name": "[variables('storageAccountName')]",
"location": "[parameters('location')]",
"sku": {
"name": "Standard_LRS"
},
"kind": "StorageV2",
"properties": {
"accessTier": "Hot",
"defaultToOAuthAuthentication": true,
"allowSharedKeyAccess": false
}
}
]
}
},
"resourceGroup": "[variables('resourceGroupNameResolved')]",
"dependsOn": [
"[concat('deploynwtarg-', uniqueString(subscription().subscriptionId, parameters('location')))]"
]
}
]
},
"parameters": {
"location": {
"value": "[parameters('location')]"
},
"resourceGroupName": {
"value": "[parameters('resourceGroupName')]"
}
}
}
}
}
}
},
"versions": [
"1.0.0"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/1c46fa74-ad5c-46e4-9cf3-6bf88e3adcba",
"name": "1c46fa74-ad5c-46e4-9cf3-6bf88e3adcba"
}Bylaw1c46fa74-ad5c-46e4-9cf3-6bf88e3adcba.bylaw.ps1 · 48 lines
# Converted from VirtualNetwork_Flowlog_TrafficAnalytics_StorageAccount_DINE.json by ConvertTo-Bylaw.
Policy '1c46fa74-ad5c-46e4-9cf3-6bf88e3adcba' {
Properties @{
DisplayName = 'Create regional Storage Account for VNet Flowlogs in resourceGroupName RG'
Description = 'Creates a regional Storage Account 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 storage account 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 Location @{
Type = 'String'
DisplayName = 'Storage Account Location'
Description = 'Location where the Storage Account exists or will be created in. It should match the location of the Virtual Network where flowlog is to be enabled.'
Metadata = [ordered]@{ strongType = 'location' }
}
Resource 'Microsoft.Resources/subscriptions'
DeployIfNotExists 'Microsoft.Storage/storageAccounts' -Role 'Contributor' -Name (Arm '[toLower(concat(''nwtasa'', uniqueString(concat(subscription().subscriptionId, parameters(''location'')))))]') -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.Storage/storageAccounts/'', toLower(concat(''nwtasa'', uniqueString(concat(subscription().subscriptionId, parameters(''location''))))))]')
Field location | Must -Be (Param Location)
}
Deployment @{
TemplateFile = './templates/1c46fa74-ad5c-46e4-9cf3-6bf88e3adcba.json'
Scope = 'Subscription'
Location = 'eastus'
Parameters = [ordered]@{
location = (Param Location)
resourceGroupName = (Param ResourceGroupName)
}
}
}
}Its deployment templates are written beside it:
templates/1c46fa74-ad5c-46e4-9cf3-6bf88e3adcba.json
Source: built-in-policies/policyDefinitions/Network/VirtualNetwork_Flowlog_TrafficAnalytics_StorageAccount_DINE.json in Azure/azure-policy, under the MIT licence.
Bylaw