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 Jun 12, 2024
1 parent 83362b5 commit e985f63
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 28 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 @@ -28,10 +28,10 @@ module "escalation" {
owner_team_id = module.owner_team.team_id

rule = {
recipients = [{
recipient = {
type = "team"
id = module.escalation_team.team_id
}]
}
}
}
}
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
10 changes: 3 additions & 7 deletions modules/escalation/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@ resource "opsgenie_escalation" "this" {
notify_type = try(var.escalation.rule.notify_type, "default")
delay = try(var.escalation.rule.delay, 0)

dynamic "recipient" {
for_each = try(var.escalation.rule.recipients, [])

content {
id = recipient.value.id
type = recipient.value.type
}
recipient {
type = recipient.value.type
id = recipient.value.id
}
}

Expand Down

0 comments on commit e985f63

Please sign in to comment.