Skip to content

Commit

Permalink
Add more items to notification policy resource
Browse files Browse the repository at this point in the history
Adds the following structures to notification policy:

- de_duplication_action
- delay-action

Reference:
https://registry.terraform.io/providers/opsgenie/opsgenie/latest/docs/resources/notification_policy#delay_action
  • Loading branch information
diraol committed Nov 30, 2023
1 parent e26788a commit ea51937
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 1 deletion.
12 changes: 12 additions & 0 deletions examples/config/resources/notification_policies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,15 @@ notification_policies:
- field: priority
operation: less-than
expected_value: P3
de_duplication_action:
de_duplication_action_type: frequency-based
count: 2
duration:
time_unit: minutes
time_amount: 5

delay_action:
delay_option: for-duration
duration:
time_unit: minutes
time_amount: 5
17 changes: 17 additions & 0 deletions examples/notification_policy/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ module "notification_policy" {
}]
}

de_duplication_action = {
de_duplication_action_type = "frequency-based"
count = 2
duration = {
time_unit = "minutes"
time_amount = 5
}
}

delay_action = {
delay_option = "for-duration"
duration = {
time_unit = "minutes"
time_amount = 10
}
}

auto_close_action = {
time_unit = "minutes"
time_amount = 5
Expand Down
19 changes: 18 additions & 1 deletion modules/notification_policy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ module "notification_policy" {
}]
}
de_duplication_action = {
de_duplication_action_type = "frequency-based"
count = 2
duration = {
time_unit = "minutes"
time_amount = 5
}
}
delay_action = {
delay_option = "for-duration"
duration = {
time_unit = "minutes"
time_amount = 10
}
}
auto_close_action = {
time_unit = "minutes"
time_amount = 5
Expand All @@ -36,7 +53,7 @@ module "notification_policy" {

## Inputs

**Note:** `notification_policy` is a map for two reasons:
**Note:** `notification_policy` 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
58 changes: 58 additions & 0 deletions modules/notification_policy/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,64 @@ resource "opsgenie_notification_policy" "this" {
}
}

time_restriction {
type = try(var.notification_policy.time_restriction.type, null)

dynamic "restrictions" {
for_each = try(var.notification_policy.filter.conditions, [])

content {
start_day = try(conditions.value.start_day, null)
end_day = try(conditions.value.end_day, null)
start_hour = try(conditions.value.start_hour, null)
end_hour = try(conditions.value.end_hour, null)
start_min = try(conditions.value.start_min, null)
end_min = try(conditions.value.end_min, null)
}
}
}

dynamic "de_duplication_action" {
for_each = try(var.notification_policy.de_duplication_action, null) != null ? ["true"] : []

content {
de_duplication_action_type = var.notification_policy.de_duplication_action.de_duplication_action_type
count = var.notification_policy.de_duplication_action.count

dynamic "duration" {
for_each = var.notification_policy.de_duplication_action.de_duplication_action_type == "frequency-based" ? ["true"] : [try(var.notification_policy.de_duplication_action.duration, null)]

content {
time_amount = var.notification_policy.de_duplication_action.duration.time_amount
time_unit = try(var.notification_policy.de_duplication_action.duration.time_unit, null)
}
}

until_hour = var.notification_policy.delay_action.delay_option != "for-duration" ? var.notification_policy.delay_action.until_hour : null
until_minute = var.notification_policy.delay_action.delay_option != "for-duration" ? var.notification_policy.delay_action.until_minute : null
}
}

dynamic "delay_action" {
for_each = try(var.notification_policy.delay_action, null) != null ? ["true"] : []

content {
delay_option = var.notification_policy.delay_action.delay_option

dynamic "duration" {
for_each = var.notification_policy.delay_action.delay_option == "for-duration" ? ["true"] : []

content {
time_amount = var.notification_policy.delay_action.duration.time_amount
time_unit = try(var.notification_policy.delay_action.duration.time_unit, null)
}
}

until_hour = var.notification_policy.delay_action.delay_option != "for-duration" ? var.notification_policy.delay_action.until_hour : null
until_minute = var.notification_policy.delay_action.delay_option != "for-duration" ? var.notification_policy.delay_action.until_minute : null
}
}

auto_close_action {
duration {
time_amount = try(var.notification_policy.auto_close_action.time_amount, null)
Expand Down

0 comments on commit ea51937

Please sign in to comment.