From 6febfe54b9d7f5f48b43521f588b17acdd012fa4 Mon Sep 17 00:00:00 2001 From: Matt Moore Date: Fri, 22 Dec 2023 10:25:20 -0500 Subject: [PATCH] Make `alerts` a list and use a `for_each`. (#29) This avoids the need to sprinkle `var.alert != ""` everywhere. Signed-off-by: Matt Moore --- dashboard/sections/alerts/main.tf | 6 +++--- dashboard/service/README.md | 2 +- dashboard/service/dashboard.tf | 6 ++++-- dashboard/service/variables.tf | 6 +++--- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/dashboard/sections/alerts/main.tf b/dashboard/sections/alerts/main.tf index 85377b2c..c0aedac9 100644 --- a/dashboard/sections/alerts/main.tf +++ b/dashboard/sections/alerts/main.tf @@ -6,7 +6,7 @@ module "width" { source = "../width" } module "alert" { source = "../../widgets/alert" - title = "Alert" + title = var.title alert_name = var.alert } @@ -25,8 +25,8 @@ module "collapsible" { // If no alert is defined, this is an empty collapsed section. title = var.title - tiles = var.alert == "" ? [] : local.tiles - collapsed = var.collapsed || var.alert == "" + tiles = local.tiles + collapsed = var.collapsed } output "section" { diff --git a/dashboard/service/README.md b/dashboard/service/README.md index a8fba32e..e3b159b6 100644 --- a/dashboard/service/README.md +++ b/dashboard/service/README.md @@ -69,7 +69,7 @@ No requirements. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| -| [alert](#input\_alert) | Alerting policies to add to the dashboard. | `string` | `""` | no | +| [alerts](#input\_alerts) | Alerting policies to add to the dashboard. | `list(string)` | `[]` | no | | [labels](#input\_labels) | Additional labels to apply to the dashboard. | `map` | `{}` | no | | [service\_name](#input\_service\_name) | Name of the service(s) to monitor | `string` | n/a | yes | diff --git a/dashboard/service/dashboard.tf b/dashboard/service/dashboard.tf index bb3aa1be..c3b7ff5c 100644 --- a/dashboard/service/dashboard.tf +++ b/dashboard/service/dashboard.tf @@ -17,8 +17,10 @@ module "resources" { } module "alerts" { + for_each = toset(var.alerts) + source = "../sections/alerts" - alert = var.alert + alert = each.key title = "Alert" } @@ -27,7 +29,7 @@ module "width" { source = "../sections/width" } module "layout" { source = "../sections/layout" sections = concat( - var.alert == "" ? [] : [module.alerts.section], + [for x in var.alerts : module.alerts[x].section], [ module.logs.section, module.http.section, diff --git a/dashboard/service/variables.tf b/dashboard/service/variables.tf index 1124ce6e..ba152ec4 100644 --- a/dashboard/service/variables.tf +++ b/dashboard/service/variables.tf @@ -8,9 +8,9 @@ variable "labels" { default = {} } -variable "alert" { +variable "alerts" { description = "Alerting policies to add to the dashboard." - type = string - default = "" + type = list(string) + default = [] }