Skip to content

Commit

Permalink
feat: variable for diagnostic setting metric (#53)
Browse files Browse the repository at this point in the history
* feat: variable for diagnostic settng metric

* fmt fix
  • Loading branch information
kov117 authored Feb 22, 2024
1 parent 0d568b9 commit 809263b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
13 changes: 10 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ locals {
# If identity_ids is non-empty, value is "UserAssigned".
# If system_assigned_identity_enabled is true and identity_ids is non-empty, value is "SystemAssigned, UserAssigned".
identity_type = join(", ", compact([var.system_assigned_identity_enabled ? "SystemAssigned" : "", length(local.identity_ids) > 0 ? "UserAssigned" : ""]))

diagnostic_setting_metric_categories = ["AllMetrics"]
}

resource "azurerm_linux_function_app" "this" {
Expand Down Expand Up @@ -162,8 +164,13 @@ resource "azurerm_monitor_diagnostic_setting" "this" {
}
}

metric {
category = "AllMetrics"
enabled = true
dynamic "metric" {
for_each = toset(concat(local.diagnostic_setting_metric_categories, var.diagnostic_setting_enabled_metric_categories))

content {
# Azure expects explicit configuration of both enabled and disabled metric categories.
category = metric.value
enabled = contains(var.diagnostic_setting_enabled_metric_categories, metric.value)
}
}
}
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ variable "diagnostic_setting_enabled_log_categories" {
default = ["FunctionAppLogs"]
}

variable "diagnostic_setting_enabled_metric_categories" {
description = "A list of metric categories to be enabled for this diagnostic setting."
type = list(string)
default = []
}

variable "kind" {
description = "The kind of Function App to create."
type = string
Expand Down

0 comments on commit 809263b

Please sign in to comment.