Gallery › Network › Azure built-in policies
Virtual networks should use specified virtual network gateway
Converted Policy AuditIfNotExists Disabled Mode Indexed Version 1.0.0
This policy audits any virtual network if the default route does not point to the specified virtual network gateway.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONVirtualApprovedVirtualNetworkGateway_AINE.json · 58 lines
{
"properties": {
"displayName": "Virtual networks should use specified virtual network gateway",
"policyType": "BuiltIn",
"mode": "Indexed",
"description": "This policy audits any virtual network if the default route does not point to the specified virtual network gateway.",
"metadata": {
"version": "1.0.0",
"category": "Network"
},
"version": "1.0.0",
"parameters": {
"effect": {
"type": "string",
"defaultValue": "AuditIfNotExists",
"allowedValues": [
"AuditIfNotExists",
"Disabled"
],
"metadata": {
"displayName": "Effect",
"description": "Enable or disable the execution of the policy"
}
},
"virtualNetworkGatewayId": {
"type": "string",
"metadata": {
"displayName": "Virtual network gateway Id",
"description": "Resource Id of the virtual network gateway. Example: /subscriptions/YourSubscriptionId/resourceGroups/YourResourceGroup/providers/Microsoft.Network/virtualNetworkGateways/Name"
}
}
},
"policyRule": {
"if": {
"field": "type",
"equals": "Microsoft.Network/virtualNetworks"
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.Network/virtualNetworks/subnets",
"name": "GatewaySubnet",
"existenceCondition": {
"not": {
"field": "Microsoft.Network/virtualNetworks/subnets/ipConfigurations[*].id",
"notContains": "[concat(parameters('virtualNetworkGatewayId'), '/')]"
}
}
}
}
},
"versions": [
"1.0.0"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/f1776c76-f58c-4245-a8d0-2b207198dc8b",
"name": "f1776c76-f58c-4245-a8d0-2b207198dc8b"
}Bylawf1776c76-f58c-4245-a8d0-2b207198dc8b.bylaw.ps1 · 35 lines
# Converted from VirtualApprovedVirtualNetworkGateway_AINE.json by ConvertTo-Bylaw.
Policy 'f1776c76-f58c-4245-a8d0-2b207198dc8b' {
Properties @{
DisplayName = 'Virtual networks should use specified virtual network gateway'
Description = 'This policy audits any virtual network if the default route does not point to the specified virtual network gateway.'
Version = '1.0.0'
Category = 'Network'
PolicyVersion = '1.0.0'
Mode = 'Indexed'
}
Parameter Effect @{
Type = 'string'
AllowedValues = @('AuditIfNotExists', 'Disabled')
Default = 'AuditIfNotExists'
DisplayName = 'Effect'
Description = 'Enable or disable the execution of the policy'
}
Parameter VirtualNetworkGatewayId @{
Type = 'string'
DisplayName = 'Virtual network gateway Id'
Description = 'Resource Id of the virtual network gateway. Example: /subscriptions/YourSubscriptionId/resourceGroups/YourResourceGroup/providers/Microsoft.Network/virtualNetworkGateways/Name'
}
Resource 'Microsoft.Network/virtualNetworks'
AuditIfNotExists 'Microsoft.Network/virtualNetworks/subnets' -Name 'GatewaySubnet' -Effect (Param Effect) {
Require 'ipConfigurations and id are as required' {
Count 'ipConfigurations[*]' -Where {
Field id | Must -ContainText (Arm '[concat(parameters(''virtualNetworkGatewayId''), ''/'')]')
} | Must -BeGreaterThan 0
}
}
}Source: built-in-policies/policyDefinitions/Network/VirtualApprovedVirtualNetworkGateway_AINE.json in Azure/azure-policy, under the MIT licence.
Bylaw