/terraform-azurerm-diagnostic-settings

Fork of the `terraform-azurerm-diagnostic-settings` module with Claranet's contributions and improvements.

Primary LanguageHCLApache License 2.0Apache-2.0

Azure Diagnostic Settings

Changelog Notice Apache V2 License TF Registry

This module is based on work from Innovation Norway.

This Terraform enables the Diagnostic Settings on a given Azure resource.

Version compatibility

Module version Terraform version AzureRM version
>= 4.x.x 0.13.x >= 2.0
>= 3.x.x 0.12.x >= 2.0
>= 2.x.x 0.12.x < 2.0
< 2.x.x 0.11.x < 2.0

Usage

You can use this module by including it this way:

data "azurerm_resources" "resources" {
  ...
}

resource "azurerm_storage_account" "logs" {
  ...
}

resource "azurerm_log_analytics_workspace" "logs" {
  ...
}

resource "azurerm_eventhub_namespace" "logs" {
  ...
}

resource "azurerm_eventhub" "logs" {
  ...
}

resource "azurerm_eventhub_authorization_rule" "logs" {
  ...
}

module "diagnostic-settings" {
  for_each = data.azurerm_resources.resources

  source  = "claranet/diagnostic-settings/azurerm"
  version = "x.x.x"

  resource_id = each.value.id

  logs_destinations_ids = [
    azurerm_storage_account.logs.id,
    azurerm_log_analytics_workspace.example.id,
    azurerm_eventhub_authorization_rule.logs.id,
  ]
  log_analytics_destination_type = "Dedicated"

}

Inputs

Name Description Type Default Required
eventhub_name Event Hub name if one of the destinations is an Event Hub. string null no
log_analytics_destination_type When set to 'Dedicated' logs sent to a Log Analytics workspace will go into resource specific tables, instead of the legacy AzureDiagnostics table. This only includes Azure Data Factory string "AzureDiagnostics" no
log_categories List of log categories. list(string) null no
logs_destinations_ids List of destination resources IDs for logs diagnostic destination. Can be Storage Account, Log Analytics Workspace and Event Hub. No more than one of each can be set. list(string) n/a yes
metric_categories List of metric categories. list(string) null no
name The name of the diagnostic setting. string "default" no
resource_id The ID of the resource on which activate the diagnostic settings. string n/a yes
retention_days The number of days to keep diagnostic logs. number 30 no

Outputs

Name Description
diagnostic_settings_id ID of the Diagnostic Settings.

Related documentation

Terraform documentation: terraform.io/docs/providers/azurerm/r/monitor_diagnostic_setting.html