Bylaw

Gallery › Network › Azure built-in policies

Network Watcher should be enabled

Converted Policy AuditIfNotExists Disabled Mode All Version 3.0.0

Network Watcher is a regional service that enables you to monitor and diagnose conditions at a network scenario level in, to, and from Azure. Scenario level monitoring enables you to diagnose problems at an end to end network level view. It is required to have a network watcher resource group to be created in every region where a virtual network is present. An alert is enabled if a network watcher resource group is not available in a particular region.

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

Azure Policy JSONNetworkWatcher_Enabled_Audit.json · 67 lines
{
  "properties": {
    "displayName": "Network Watcher should be enabled",
    "policyType": "BuiltIn",
    "mode": "All",
    "description": "Network Watcher is a regional service that enables you to monitor and diagnose conditions at a network scenario level in, to, and from Azure. Scenario level monitoring enables you to diagnose problems at an end to end network level view. It is required to have a network watcher resource group to be created in every region where a virtual network is present. An alert is enabled if a network watcher resource group is not available in a particular region.",
    "metadata": {
      "version": "3.0.0",
      "category": "Network"
    },
    "version": "3.0.0",
    "parameters": {
      "effect": {
        "type": "string",
        "defaultValue": "AuditIfNotExists",
        "allowedValues": [
          "AuditIfNotExists",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      },
      "listOfLocations": {
        "type": "Array",
        "metadata": {
          "displayName": "Locations",
          "description": "Audit if Network Watcher is not enabled for region(s).",
          "strongType": "location",
          "deprecated": true
        },
        "defaultValue": []
      },
      "resourceGroupName": {
        "type": "String",
        "metadata": {
          "displayName": "NetworkWatcher resource group name",
          "description": "Name of the resource group of NetworkWatcher, such as NetworkWatcherRG. This is the resource group where the Network Watchers are located."
        },
        "defaultValue": "NetworkWatcherRG"
      }
    },
    "policyRule": {
      "if": {
        "field": "type",
        "equals": "Microsoft.Network/virtualNetworks"
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.Network/networkWatchers",
          "resourceGroupName": "[parameters('resourceGroupName')]",
          "existenceCondition": {
            "field": "location",
            "equals": "[field('location')]"
          }
        }
      }
    },
    "versions": [
      "3.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/b6e2945c-0b7b-40f5-9233-7a5323b5cdc6",
  "name": "b6e2945c-0b7b-40f5-9233-7a5323b5cdc6"
}
Bylawb6e2945c-0b7b-40f5-9233-7a5323b5cdc6.bylaw.ps1 · 40 lines
# Converted from NetworkWatcher_Enabled_Audit.json by ConvertTo-Bylaw.
Policy 'b6e2945c-0b7b-40f5-9233-7a5323b5cdc6' {

    Properties @{
        DisplayName   = 'Network Watcher should be enabled'
        Description   = 'Network Watcher is a regional service that enables you to monitor and diagnose conditions at a network scenario level in, to, and from Azure. Scenario level monitoring enables you to diagnose problems at an end to end network level view. It is required to have a network watcher resource group to be created in every region where a virtual network is present. An alert is enabled if a network watcher resource group is not available in a particular region.'
        Version       = '3.0.0'
        Category      = 'Network'
        PolicyVersion = '3.0.0'
        Mode          = 'All'
    }

    Parameter Effect @{
        Type          = 'string'
        AllowedValues = @('AuditIfNotExists', 'Disabled')
        Default       = 'AuditIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }
    Parameter ListOfLocations @{
        Type        = 'Array'
        Default     = @()
        DisplayName = 'Locations'
        Description = 'Audit if Network Watcher is not enabled for region(s).'
        Metadata    = [ordered]@{ strongType = 'location'; deprecated = $true }
    }
    Parameter ResourceGroupName @{
        Default     = 'NetworkWatcherRG'
        DisplayName = 'NetworkWatcher resource group name'
        Description = 'Name of the resource group of NetworkWatcher, such as NetworkWatcherRG. This is the resource group where the Network Watchers are located.'
    }

    Resource 'Microsoft.Network/virtualNetworks'

    AuditIfNotExists 'Microsoft.Network/networkWatchers' -ResourceGroupName (Param ResourceGroupName) -Effect (Param Effect) {
        Require 'location is (Arm ''[field(''''location'''')]'')' {
            Field location | Must -Be (Arm '[field(''location'')]')
        }
    }
}

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