Skip to content

Commit

Permalink
[escalation] Set rules as the standard
Browse files Browse the repository at this point in the history
  • Loading branch information
diraol committed Jul 23, 2024
1 parent 3479e92 commit 9908e1d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions examples/escalation/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions modules/config/README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -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
```

Expand Down
6 changes: 3 additions & 3 deletions modules/config/escalations.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ 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")
notify_type = try(rules.value.notify_type, "default")
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) : (
Expand Down
2 changes: 1 addition & 1 deletion modules/escalation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module "escalation" {
name = module.label.id
owner_team_id = module.owner_team.team_id
rule = {
rules = {
recipient = {
type = "team"
id = module.escalation_team.team_id
Expand Down
2 changes: 1 addition & 1 deletion modules/escalation/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 9908e1d

Please sign in to comment.