From 835049ea0e45a126554dba123ca1969c20611614 Mon Sep 17 00:00:00 2001 From: Diego Rabatone Oliveira Date: Tue, 23 Jul 2024 16:04:10 -0300 Subject: [PATCH] [escalation] Set rules as the standard --- examples/escalation/main.tf | 4 ++-- modules/config/README.md | 12 ++++++------ modules/config/escalations.tf | 6 +++--- modules/escalation/README.md | 12 ++++++------ modules/escalation/main.tf | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/examples/escalation/main.tf b/examples/escalation/main.tf index 7fd6dad..eba9637 100644 --- a/examples/escalation/main.tf +++ b/examples/escalation/main.tf @@ -31,12 +31,12 @@ module "escalation" { name = module.this.id owner_team_id = module.owner_team.team_id - rule = { + rules = [{ recipient = { type = "team" id = module.escalation_team.team_id } - } + }] } context = module.this.context diff --git a/modules/config/README.md b/modules/config/README.md index 4e22ebe..0f92f7d 100644 --- a/modules/config/README.md +++ b/modules/config/README.md @@ -1,10 +1,10 @@ ## Config -Terraform module that configures a multitude of [Opsgenie resources](https://registry.terraform.io/providers/opsgenie/opsgenie/latest/docs). +Terraform module that configures a multitude of [Opsgenie resources](https://registry.terraform.io/providers/opsgenie/opsgenie/latest/docs). Many resources have cross-resource dependencies, which may be simpler to handle within a single module in certain cases, such as using YAML configurations. -This module is designed to accept an input configuration map. -One nice way of handling this is by passing resource definitions from a YAML configuration file. +This module is designed to accept an input configuration map. +One nice way of handling this is by passing resource definitions from a YAML configuration file. See below for details & examples. @@ -46,12 +46,12 @@ escalations: - name: acme.dev.some-service-escalation description: "repo: https://github.com/acme/some-service;owner:David Lightman @David Lightman" owner_team_name: acme.dev - rule: - condition: if-not-acked + rules: + - condition: if-not-acked notify_type: default delay: 0 recipient: - - type: team + type: team team_name: acme.dev.some-service ``` diff --git a/modules/config/escalations.tf b/modules/config/escalations.tf index d44610a..cb435df 100644 --- a/modules/config/escalations.tf +++ b/modules/config/escalations.tf @@ -8,7 +8,7 @@ resource "opsgenie_escalation" "this" { owner_team_id = try(opsgenie_team.this[each.value.owner_team_name].id, null) dynamic "rules" { - for_each = try([each.value.rules], []) + for_each = try(each.value.rules, []) content { condition = try(rules.value.condition, "if-not-acked") @@ -16,9 +16,9 @@ resource "opsgenie_escalation" "this" { delay = try(rules.value.delay, 0) recipient { - type = rules.value.recipient["type"] + type = rules.value.recipient.type - id = lookup(rules.value.recipient, "id", null) != null ? rules.value.recipient.id : ( + id = try(rules.value.recipient.id, null) != null ? rules.value.recipient.id : ( rules.value.recipient.type == "team" ? try(opsgenie_team.this[rules.value.recipient.team_name].id, data.opsgenie_team.this[rules.value.recipient.team_name].id) : ( rules.value.recipient.type == "user" ? try(opsgenie_user.this[rules.value.recipient.user_name].id, data.opsgenie_user.this[rules.value.recipient.user_name].id) : ( rules.value.recipient.type == "schedule" ? try(opsgenie_schedule.this[rules.value.recipient.schedule_name].id, data.opsgenie_schedule.this[rules.value.recipient.schedule_name].id) : ( diff --git a/modules/escalation/README.md b/modules/escalation/README.md index c0dc86d..d21d335 100644 --- a/modules/escalation/README.md +++ b/modules/escalation/README.md @@ -17,12 +17,12 @@ module "escalation" { name = module.label.id owner_team_id = module.owner_team.team_id - rule = { - recipient = { - type = "team" - id = module.escalation_team.team_id - } - } + rules = [{ + recipient = { + type = "team" + id = module.escalation_team.team_id + } + }] } } diff --git a/modules/escalation/main.tf b/modules/escalation/main.tf index 244e718..6c65e8a 100644 --- a/modules/escalation/main.tf +++ b/modules/escalation/main.tf @@ -6,7 +6,7 @@ resource "opsgenie_escalation" "this" { owner_team_id = try(var.escalation.owner_team_id, null) dynamic "rules" { - for_each = try(var.escalation.rule, []) + for_each = try(var.escalation.rules, []) content { condition = try(rules.value.condition, "if-not-acked")