Skip to content

Commit

Permalink
[escalation] Single recipient per rule
Browse files Browse the repository at this point in the history
Opsgenie only accepts a single recipient per rule.
Worst than that, if we send more than one recipient, OpsGenie API will
accept the payload will add only the first recipient and will return
200.
  • Loading branch information
diraol committed Jul 23, 2024
1 parent 08a701f commit f3e8ced
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 34 deletions.
4 changes: 2 additions & 2 deletions examples/config/resources/escalations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ escalations:
condition: if-not-acked
notify_type: default
delay: 0
recipients:
- type: team
recipient:
type: team
team_name: acme.dev.some-service
4 changes: 2 additions & 2 deletions examples/escalation/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ module "escalation" {
owner_team_id = module.owner_team.team_id

rule = {
recipients = [{
recipient = {
type = "team"
id = module.escalation_team.team_id
}]
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion modules/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ escalations:
condition: if-not-acked
notify_type: default
delay: 0
recipients:
recipient:
- type: team
team_name: acme.dev.some-service
```
Expand Down
22 changes: 9 additions & 13 deletions modules/config/escalations.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,18 @@ resource "opsgenie_escalation" "this" {
notify_type = try(rules.value.notify_type, "default")
delay = try(rules.value.delay, 0)

dynamic "recipient" {
for_each = try(rules.value.recipients, [])

content {
type = recipient.value.type

id = lookup(recipient.value, "id", null) != null ? recipient.value.id : (
recipient.value.type == "team" ? opsgenie_team.this[recipient.value.team_name].id : (
recipient.value.type == "user" ? try(opsgenie_user.this[recipient.value.user_name].id, data.opsgenie_user.this[recipient.value.user_name].id) : (
recipient.value.type == "schedule" ? opsgenie_schedule.this[recipient.value.schedule_name].id : (
null
)
recipient {
type = rules.value.recipient.type

id = lookup(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) : (
null
)
)
)
}
)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions modules/escalation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ module "escalation" {
owner_team_id = module.owner_team.team_id
rule = {
recipients = [{
recipient = {
type = "team"
id = module.escalation_team.team_id
}]
}
}
}
Expand All @@ -31,7 +31,7 @@ module "escalation" {

## Inputs

**Note:** `escalation` is a map for two reasons:
**Note:** `escalation` is a map for two reasons:
- to be able to put whole configuration in yaml file
- variables defined with type set are not robust enough (can't set default values)

Expand Down
26 changes: 13 additions & 13 deletions modules/escalation/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ resource "opsgenie_escalation" "this" {
description = try(var.escalation.description, var.escalation.name)
owner_team_id = try(var.escalation.owner_team_id, null)

rules {
condition = try(var.escalation.rule.condition, "if-not-acked")
notify_type = try(var.escalation.rule.notify_type, "default")
delay = try(var.escalation.rule.delay, 0)
dynamic "rules" {
for_each = try(var.escalation.rule, [])

dynamic "recipient" {
for_each = try(var.escalation.rule.recipients, [])
content {
condition = try(rules.value.condition, "if-not-acked")
notify_type = try(rules.value.notify_type, "default")
delay = rules.value.delay

content {
id = recipient.value.id
type = recipient.value.type
recipient {
type = rules.value.recipient.type
id = try(rules.value.recipient.id, null)
}
}
}
Expand All @@ -24,10 +24,10 @@ resource "opsgenie_escalation" "this" {
for_each = try(var.escalation.repeat, null) != null ? ["true"] : []

content {
wait_interval = lookup(var.escalation.repeat, "wait_interval", 5)
count = lookup(var.escalation.repeat, "count", 0)
reset_recipient_states = lookup(var.escalation.repeat, "reset_recipient_states", true)
close_alert_after_all = lookup(var.escalation.repeat, "close_alert_after_all", true)
wait_interval = try(var.escalation.repeat.wait_interval, 5)
count = try(var.escalation.repeat.count, 0)
reset_recipient_states = try(var.escalation.repeat.reset_recipient_states, true)
close_alert_after_all = try(var.escalation.repeat.close_alert_after_all, true)
}
}
}

0 comments on commit f3e8ced

Please sign in to comment.