Skip to content

Commit

Permalink
Make alerts a list and use a for_each.
Browse files Browse the repository at this point in the history
This avoids the need to sprinkle `var.alert != ""` everywhere.

Signed-off-by: Matt Moore <[email protected]>
  • Loading branch information
mattmoor committed Dec 22, 2023
1 parent 1f49244 commit a82e40c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions dashboard/sections/alerts/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module "width" { source = "../width" }

module "alert" {
source = "../../widgets/alert"
title = "Alert"
title = var.title
alert_name = var.alert
}

Expand All @@ -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" {
Expand Down
2 changes: 1 addition & 1 deletion dashboard/service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ No requirements.

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_alert"></a> [alert](#input\_alert) | Alerting policies to add to the dashboard. | `string` | `""` | no |
| <a name="input_alerts"></a> [alerts](#input\_alerts) | Alerting policies to add to the dashboard. | `list(string)` | `[]` | no |
| <a name="input_labels"></a> [labels](#input\_labels) | Additional labels to apply to the dashboard. | `map` | `{}` | no |
| <a name="input_service_name"></a> [service\_name](#input\_service\_name) | Name of the service(s) to monitor | `string` | n/a | yes |

Expand Down
6 changes: 4 additions & 2 deletions dashboard/service/dashboard.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ module "resources" {
}

module "alerts" {
for_each = toset(var.alerts)

source = "../sections/alerts"
alert = var.alert
alert = ech.key
title = "Alert"
}

Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions dashboard/service/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
}

0 comments on commit a82e40c

Please sign in to comment.