Review Azure flow-log retention

Check the flow-log retention needed for investigations and the storage account’s actual deletion policies.

Description

For an existing NSG flow log, check both retention_policy and the storage account’s lifecycle policy. Retention controls when stored records expire. Flow-log collection has its own setting.

Potential impact

If network records expire early, investigators may be unable to reconstruct communication during an incident or compare it with previous traffic.

Remediation

Choose a period based on audit and investigation needs and storage costs. Check for earlier deletion policies and confirm that investigators can read recent logs and the oldest available records. Azure stopped accepting new NSG flow logs after June 30, 2025. Migrate existing configurations to virtual network flow logs before September 30, 2027, and verify retention there.

Examples

These older AzureRM excerpts apply to an existing NSG flow log. They omit the flow log name and the definitions of the referenced resources.

Before

hcl
resource "azurerm_network_watcher_flow_log" "example" {
  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

  retention_policy {
    enabled = true
    days    = 89
  }
}

After

hcl
resource "azurerm_network_watcher_flow_log" "example" {
  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

  retention_policy {
    enabled = true
    days    = 90
  }
}

Both excerpts enable collection and retention. With a general-purpose v2 storage account, increasing 89 days to 90 meets the example target going forward. Records already deleted cannot be recovered.

References