Skip to content

Commit

Permalink
Vnet diagnostic settings
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtiomMatiom committed Jul 8, 2024
1 parent e65e2a0 commit 07fab1a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
31 changes: 31 additions & 0 deletions modules/azure/virtual_network/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,34 @@ resource "azurerm_virtual_network" "virtual_network" {
ignore_changes = [subnet]
}
}


data "azurerm_monitor_diagnostic_categories" "diagnostic_categories" {
count = var.loganalytics_diagnostic_setting == null ? 0 : 1
resource_id = azurerm_virtual_network.virtual_network.id
}

resource "azurerm_monitor_diagnostic_setting" "diagnostic_setting" {
count = var.loganalytics_diagnostic_setting == null ? 0 : 1
name = "diag-${var.name}"
target_resource_id = azurerm_virtual_network.virtual_network.id
log_analytics_workspace_id = var.loganalytics_diagnostic_setting.workspace_id


dynamic "enabled_log" {
for_each = var.loganalytics_diagnostic_setting.categories == null ? data.azurerm_monitor_diagnostic_categories.diagnostic_categories[0].log_category_types : var.loganalytics_diagnostic_setting.categories

content {
category = enabled_log.value
}
}

dynamic "metric" {
for_each = var.loganalytics_diagnostic_setting.metrics == null ? data.azurerm_monitor_diagnostic_categories.diagnostic_categories[0].metrics : var.loganalytics_diagnostic_setting.metrics

content {
category = metric.value
enabled = true
}
}
}
10 changes: 10 additions & 0 deletions modules/azure/virtual_network/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,13 @@ variable "address_space" {
type = list(string)
description = "Address space of the virtual network."
}

variable "loganalytics_diagnostic_setting" {
type = object({
workspace_id = string, // log analytics workspace ID
categories = optional(list(string)), // null list,means send all categories
metrics = optional(list(string)), // null list means send all metrics
})
description = "Specifies the log categories that have to be sent to Log analytics."
default = null
}

0 comments on commit 07fab1a

Please sign in to comment.