Skip to content

Commit

Permalink
service plan diagnostic settings
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtiomMatiom committed Jul 8, 2024
1 parent ab857f2 commit 3d8bc6a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
32 changes: 32 additions & 0 deletions modules/azure/service_plan/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,35 @@ resource "azurerm_monitor_autoscale_setting" "autoscale_setting" {
}
}
}


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

resource "azurerm_monitor_diagnostic_setting" "diagnostic_setting" {
count = var.loganalytics_diagnostic_setting == null ? 0 : 1
name = "diag-${var.name}"
target_resource_id = azurerm_service_plan.sp.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
}
}
}

11 changes: 11 additions & 0 deletions modules/azure/service_plan/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,14 @@ variable "scaling_rules" {
}
]
}


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 3d8bc6a

Please sign in to comment.