Review Azure resource diagnostic settings

Configure the required Azure diagnostic logs and destinations, then verify collection.

Description

Azure collects subscription Activity Logs and platform metrics automatically. Export the records you need for central investigations or to keep Activity Logs beyond their default 90 days.

Potential impact

Resource log collection depends on the service. Gaps in your central logs can make it harder to trace a problem across resources.

Remediation

Check existing collection paths and any service-specific logging requirements. In azurerm_monitor_diagnostic_setting, select supported logs or metrics and a destination such as Log Analytics, Event Hubs or a storage account. For Administrative, as shown, find the record of an approved resource change in the workspace. Check destination retention, read access and cost.

Examples

The excerpts use an existing subscription and Log Analytics workspace. Looking up the subscription in the first excerpt does not show any diagnostic settings configured elsewhere.

Before

hcl
data "azurerm_subscription" "example" {}

After

hcl
data "azurerm_subscription" "example" {}

resource "azurerm_monitor_diagnostic_setting" "example" {
  name               = "subscription-diagnostics"
  target_resource_id = data.azurerm_subscription.example.id
  log_analytics_workspace_id = azurerm_log_analytics_workspace.example.id

  enabled_log {
    category = "Administrative"
  }
}

The second setting exports only the subscription’s Administrative category.

References