Azure Network Watcher Flow Log
This page shows how to write Terraform and Azure Resource Manager for Network Watcher Flow Log and write them securely.
azurerm_network_watcher_flow_log (Terraform)
The Watcher Flow Log in Network can be configured in Terraform with the resource name azurerm_network_watcher_flow_log
. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "azurerm_network_watcher_flow_log" "allowed" {
retention_policy {
enabled = true
days = 90
}
}
resource "azurerm_network_watcher_flow_log" "flowlogsaks" {
network_watcher_name = azurerm_network_watcher.flowlogs.name
resource_group_name = azurerm_resource_group.tf-security.name
network_security_group_id = azurerm_network_security_group.aks.id
storage_account_id = azurerm_storage_account.tfflowlogs.id
resource "azurerm_network_watcher_flow_log" "positive1" {
network_watcher_name = azurerm_network_watcher.test.name
resource_group_name = azurerm_resource_group.test.name
network_security_group_id = azurerm_network_security_group.test.id
storage_account_id = azurerm_storage_account.test.id
enabled = true
resource "azurerm_network_watcher_flow_log" "positive1" {
network_watcher_name = azurerm_network_watcher.test.name
resource_group_name = azurerm_resource_group.test.name
network_security_group_id = azurerm_network_security_group.test.id
storage_account_id = azurerm_storage_account.test.id
enabled = true
resource "azurerm_network_watcher_flow_log" "test" {
network_watcher_name = "NetworkWatcher_westeurope"
resource_group_name = "NetworkWatcherRG"
network_security_group_id = azurerm_network_security_group.NSG-FRONTEND[0].id
storage_account_id = azurerm_storage_account.aksflowlogmf01.id
resource "azurerm_network_watcher_flow_log" "negative1" {
network_watcher_name = azurerm_network_watcher.test.name
resource_group_name = azurerm_resource_group.test.name
network_security_group_id = azurerm_network_security_group.test.id
storage_account_id = azurerm_storage_account.test.id
enabled = true
resource "azurerm_network_watcher_flow_log" "negative1" {
network_watcher_name = azurerm_network_watcher.test.name
resource_group_name = azurerm_resource_group.test.name
network_security_group_id = azurerm_network_security_group.test.id
storage_account_id = azurerm_storage_account.test.id
enabled = true
resource "azurerm_network_watcher_flow_log" "flow_log" {
network_watcher_name = local.net_watcher_name
resource_group_name = local.resource_group_name
network_security_group_id = local.network_security_group_id
storage_account_id = local.storage_account_id
resource "azurerm_network_watcher_flow_log" "module_flow_log" {
network_watcher_name = resourcename # azurerm_network_watcher.test.name
resource_group_name = resourcegroup # azurerm_resource_group.test.name
network_security_group_id = azurerm_network_security_group.test.id
storage_account_id = azurerm_storage_account.test.id
resource "azurerm_network_watcher_flow_log" "flow" {
count = try(var.settings, {}) == {} ? 0 : 1
network_watcher_name = try(var.network_watchers[var.settings.network_watcher_key].name, format("NetworkWatcher_%s", var.resource_location))
resource_group_name = try(var.network_watchers[var.settings.network_watcher_rg_key].resource_group_name, "NetworkWatcherRG")
version = try(var.settings.version, 2)
Security Best Practices for azurerm_network_watcher_flow_log
There is 1 setting in azurerm_network_watcher_flow_log that should be taken care of for security reasons. The following section explain an overview and example code.
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.
Parameters
-
enabled
required - bool -
id
optional computed - string -
network_security_group_id
required - string -
network_watcher_name
required - string -
resource_group_name
required - string -
storage_account_id
required - string -
version
optional computed - number -
retention_policy
list block -
timeouts
single block -
traffic_analytics
list block-
enabled
required - bool -
interval_in_minutes
optional - number -
workspace_id
required - string -
workspace_region
required - string -
workspace_resource_id
required - string
-
Explanation in Terraform Registry
Manages a Network Watcher Flow Log.
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.
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.
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.
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
"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",
"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",
"type": "Microsoft.Network/networkWatchers",
"resourceGroupName": "networkWatcherRG",
"existenceCondition": {
"field": "location",
"equals": "[field('location')]"
},
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"input": {
"Type": "Microsoft.Network/networkWatchers",
"ResourceType": "Microsoft.Network/networkWatchers",
"ExtensionResourceType": null,
"Sku": null,
"Tags": null,
"SubscriptionId": "76c9af94-ff5d-4bbe-8e7b-228db3bd1804",
"Type": "Microsoft.Network/networkWatchers",
"ResourceType": "Microsoft.Network/networkWatchers",
"ExtensionResourceType": null,
"Sku": null,
"Tags": null,
"SubscriptionId": "d6cf79f8-681b-4d3e-82d3-dd5cc7c83604",
"Type": "Microsoft.Network/networkWatchers",
"ResourceType": "Microsoft.Network/networkWatchers",
"ExtensionResourceType": null,
"Sku": null,
"Tags": null,
"SubscriptionId": "67f16219-3421-4cef-89b9-c06cf90d7bea",
"Type": "Microsoft.Network/networkWatchers",
"ResourceType": "Microsoft.Network/networkWatchers",
"ExtensionResourceType": null,
"Sku": null,
"Tags": null,
"SubscriptionId": "d6cf79f8-681b-4d3e-82d3-dd5cc7c83604",
"type": "Microsoft.Network/networkWatchers",
"resourceGroupName": "networkWatcherRG",
"existenceCondition": {
"field": "location",
"equals": "[field('location')]"
},
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"input": {
Parameters
name
required - stringtype
required - stringapiVersion
required - stringlocation
required - stringResource location.
tags
optional - stringResource tags.
properties
required
Frequently asked questions
What is Azure Network Watcher Flow Log?
Azure Network Watcher Flow Log 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 Flow Log?
For Terraform, the snyk-labs/infrastructure-as-code-goof, mgugger/terraform and leonidweinbergcx/mykics 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.