Bylaw

Gallery › Network › Azure Community Policy

Audit if Network Watcher is not enabled for region

Converted Policy AuditIfNotExists Disabled Mode All Version 1.0.0

This policy audits if Network Watcher is not enabled for a selected region.

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

Azure Policy JSONazurepolicy.json · 52 lines
{
  "name": "ac1d63e4-7296-46f7-bdbc-738f56b5aeb3",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Audit if Network Watcher is not enabled for region",
    "description": "This policy audits if Network Watcher is not enabled for a selected region.",
    "metadata": {
      "version": "1.0.0",
      "category": "Network"
    },
    "mode": "All",
    "parameters": {
      "location": {
        "type": "string",
        "metadata": {
          "displayName": "Audit if Network Watcher is not enabled for region",
          "description": "This policy audits if Network Watcher is not enabled for a selected region.",
          "strongType": "location"
        }
      },
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "AuditIfNotExists or Disabled the execution of the Policy"
        },
        "allowedValues": [
          "AuditIfNotExists",
          "Disabled"
        ],
        "defaultValue": "AuditIfNotExists"
      }
    },
    "policyRule": {
      "if": {
        "field": "type",
        "equals": "Microsoft.Network/virtualNetworks"
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.Network/networkWatchers",
          "resourceGroupName": "NetworkWatcherRG",
          "existenceCondition": {
            "field": "location",
            "equals": "[parameters('location')]"
          }
        }
      }
    }
  }
}
Bylawac1d63e4-7296-46f7-bdbc-738f56b5aeb3.bylaw.ps1 · 32 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'ac1d63e4-7296-46f7-bdbc-738f56b5aeb3' {

    Properties @{
        DisplayName = 'Audit if Network Watcher is not enabled for region'
        Description = 'This policy audits if Network Watcher is not enabled for a selected region.'
        Version     = '1.0.0'
        Category    = 'Network'
        Mode        = 'All'
    }

    Parameter Location @{
        Type        = 'string'
        DisplayName = 'Audit if Network Watcher is not enabled for region'
        Description = 'This policy audits if Network Watcher is not enabled for a selected region.'
        Metadata    = [ordered]@{ strongType = 'location' }
    }
    Parameter Effect @{
        AllowedValues = @('AuditIfNotExists', 'Disabled')
        Default       = 'AuditIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'AuditIfNotExists or Disabled the execution of the Policy'
    }

    Resource 'Microsoft.Network/virtualNetworks'

    AuditIfNotExists 'Microsoft.Network/networkWatchers' -ResourceGroupName 'NetworkWatcherRG' -Effect (Param Effect) {
        Require 'location is the Location parameter' {
            Field location | Must -Be (Param Location)
        }
    }
}

Source: policyDefinitions/Network/audit-if-network-watcher-is-not-enabled-for-region/azurepolicy.json in Azure/Community-Policy, under the MIT licence.