Azure Network Watcher

This page shows how to write Terraform and Azure Resource Manager for Network Watcher and write them securely.

azurerm_network_watcher (Terraform)

The Watcher in Network can be configured in Terraform with the resource name azurerm_network_watcher. The following sections describe 10 examples of how to use the resource and its parameters.

Example Usage from GitHub

networkwatcher.tf#L11
resource "azurerm_network_watcher" "connectivity_westeurope" {
  provider = azurerm.Connectivity
  name                = "westeurope"
  location            = "westeurope"
  resource_group_name = azurerm_resource_group.connectivity_networkwatcher.name
}
network.tf#L65
resource "azurerm_network_watcher" "watcher" {
  name                = format("%s-watcher", local.full_env_code)
  location            = var.location
  resource_group_name = module.rg-network.name
}

resource.tf#L1
resource "azurerm_network_watcher" "nw" {
  name                = var.res_network_watcher_name
  location            = var.res_location
  resource_group_name = var.res_rg_name
networkWatchers.tf#L1
resource "azurerm_network_watcher" "example" {
  name                = "production-nwwatcher"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
network.tf#L64
resource "azurerm_network_watcher" "watcher" {
  name                = format("%s-watcher", local.full_env_code)
  location            = var.location
  resource_group_name = module.rg-network.name
}

module.tf#L12
resource "azurerm_network_watcher" "netwatcher" {
  name                = azurecaf_name.netwatcher.result
  location            = var.location
  resource_group_name = var.resource_group_name
  tags                = local.tags
}
resource.tf#L1
resource "azurerm_network_watcher" "net_watch" {
  name                = var.name
  location            = var.location
  resource_group_name = var.rg_name
  tags                = var.tags
module.tf#L12
resource "azurerm_network_watcher" "netwatcher" {
  name                = azurecaf_name.netwatcher.result
  location            = var.location
  resource_group_name = var.resource_group_name
  tags                = local.tags
}
module.tf#L2
resource "azurerm_network_watcher" "netwatcher" {
  name                = var.settings.name
  location            = var.location
  resource_group_name = var.resource_group_name
  tags                = local.tags
}
main.tf#L12
resource "azurerm_network_watcher" "net_watcher" {
  name                = local.net_watcher_name
  location            = local.location
  resource_group_name = local.resource_group_name
}

Review your Terraform file for Azure best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

Explanation in Terraform Registry

Manages a Network Watcher.

Tips: Best Practices for The Other Azure Network Resources

In addition to the azurerm_network_security_group, Azure Network has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.

risk-label

azurerm_network_security_group

Ensure to disable RDP port from the Internet

It is better to disable the RDP port from the Internet. RDP access should not be accepted from the Internet (*, 0.0.0.0, /0, internet, any), and consider using the Azure Bastion Service.

risk-label

azurerm_network_security_rule

Ensure to set a more restrictive CIDR range for ingress from the internet

It is better to set a more restrictive CIDR range not to use very broad subnets. If possible, segments should be divided into smaller subnets.

risk-label

azurerm_network_watcher_flow_log

Ensure to enable Retention policy for flow logs and set it to enough duration

It is better to enable a retention policy for flow logs. Flow logs show us all network activity in the cloud environment and support us when we face critical incidents.

Review your Azure Network settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

Microsoft.Network/networkWatchers (Azure Resource Manager)

The networkWatchers in Microsoft.Network can be configured in Azure Resource Manager with the resource name Microsoft.Network/networkWatchers. The following sections describe how to use the resource and its parameters.

Example Usage from GitHub

network_watcher.json#L10
        "type": "Microsoft.Network/networkWatchers"
    },
    {
        "etag": "W/\"1999291d-91bc-41e2-9705-74be3187e118\"",
        "id": "/subscriptions/510f92e0-3fcf-4b8f-8a23-095d37e6a299/resourceGroups/NetworkWatcherRG/providers/Microsoft.Network/networkWatchers/NetworkWatcher_eastus",
        "location": "eastus",
network_watcher.json#L10
        "type": "Microsoft.Network/networkWatchers"
    },
    {
        "etag": "W/\"1999291d-91bc-41e2-9705-74be3187e118\"",
        "id": "/subscriptions/510f92e0-3fcf-4b8f-8a23-095d37e6a299/resourceGroups/NetworkWatcherRG/providers/Microsoft.Network/networkWatchers/NetworkWatcher_eastus",
        "location": "eastus",
policy.json#L20
     "type": "Microsoft.Network/networkWatchers",
     "resourceGroupName": "networkWatcherRG",
     "existenceCondition": {
      "field": "location",
      "equals": "[field('location')]"
     },
Microsoft.Authorization_policyDefinitions-Deploy-Nsg-FlowLogs.parameters.json
{
  "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "input": {
Microsoft.Network_networkWatchers-NetworkWatcher_westeurope.parameters.json#L23
        "Type": "Microsoft.Network/networkWatchers",
        "ResourceType": "Microsoft.Network/networkWatchers",
        "ExtensionResourceType": null,
        "Sku": null,
        "Tags": null,
        "SubscriptionId": "76c9af94-ff5d-4bbe-8e7b-228db3bd1804",
Microsoft.Network_networkWatchers-NetworkWatcher_westeurope.parameters.json#L23
        "Type": "Microsoft.Network/networkWatchers",
        "ResourceType": "Microsoft.Network/networkWatchers",
        "ExtensionResourceType": null,
        "Sku": null,
        "Tags": null,
        "SubscriptionId": "d6cf79f8-681b-4d3e-82d3-dd5cc7c83604",
Microsoft.Network_networkWatchers-NetworkWatcher_westeurope.parameters.json#L23
        "Type": "Microsoft.Network/networkWatchers",
        "ResourceType": "Microsoft.Network/networkWatchers",
        "ExtensionResourceType": null,
        "Sku": null,
        "Tags": null,
        "SubscriptionId": "67f16219-3421-4cef-89b9-c06cf90d7bea",
Microsoft.Network_networkWatchers-NetworkWatcher_germanywestcentral.parameters.json#L23
        "Type": "Microsoft.Network/networkWatchers",
        "ResourceType": "Microsoft.Network/networkWatchers",
        "ExtensionResourceType": null,
        "Sku": null,
        "Tags": null,
        "SubscriptionId": "d6cf79f8-681b-4d3e-82d3-dd5cc7c83604",
Deploy-if-not-exists-DNS.json#L18
                    "type": "Microsoft.Network/networkWatchers",
                    "resourceGroupName": "networkWatcherRG",
                    "existenceCondition": {
                        "field": "location",
                        "equals": "[field('location')]"
                    },
Microsoft.Authorization_policyDefinitions-Deploy-Nsg-FlowLogs.parameters.json
{
  "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "input": {

Parameters

  • name required - string
  • type required - string
  • apiVersion required - string
  • location required - string

    Resource location.

  • tags optional - string

    Resource tags.

  • properties required

    Frequently asked questions

    What is Azure Network Watcher?

    Azure Network Watcher is a resource for Network of Microsoft Azure. Settings can be wrote in Terraform.

    Where can I find the example code for the Azure Network Watcher?

    For Terraform, the liamfoneill/NotQuiteEnterpriseScale, tmeadon/clippings and avishekansible/AzureLandingZone source code examples are useful. See the Terraform Example section for further details.

    For Azure Resource Manager, the kbroughton/azure_cis_scanner, kbroughton/azure_cis_scanner and manoj-murali/ARMTemplates source code examples are useful. See the Azure Resource Manager Example section for further details.