Description
Choose log categories supported by the diagnostic setting’s target_resource_id. The subscription Activity Log and individual resources expose different categories. Key Vault, for example, uses AuditEvent for auditing.
Potential impact
An unsupported category can prevent the setting from applying. An omitted category or incorrect destination can leave an event out of your central logs.
Remediation
Set category or a supported category_group inside an enabled_log block. Set the destination, such as log_analytics_workspace_id, on the diagnostic setting itself. Perform an operation in a selected category and check its record, read access and retention at the approved destination.
Examples
The first excerpt omits both the category and destination for Key Vault. The second targets the subscription and requires the referenced subscription and Log Analytics workspace.
Before
resource "azurerm_monitor_diagnostic_setting" "example" {
name = "diagnostic-settings-name"
target_resource_id = azurerm_key_vault.example.id
}
After
resource "azurerm_monitor_diagnostic_setting" "example" {
name = "diagnostic-settings-name"
target_resource_id = data.azurerm_subscription.example.id
log_analytics_workspace_id = azurerm_log_analytics_workspace.example.id
enabled_log {
category = "Administrative"
}
enabled_log {
category = "Alert"
}
enabled_log {
category = "Policy"
}
enabled_log {
category = "Security"
}
}
The second setting sends Administrative, Alert, Policy and Security events from the subscription to the workspace. Auditing a vault requires a separate setting on that resource.