From ea51937f7e8c2691fa78e9d7e83fd78d58cdf624 Mon Sep 17 00:00:00 2001 From: Diego Rabatone Oliveira Date: Thu, 30 Nov 2023 16:17:37 -0300 Subject: [PATCH] Add more items to notification policy resource 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 --- .../resources/notification_policies.yaml | 12 ++++ examples/notification_policy/main.tf | 17 ++++++ modules/notification_policy/README.md | 19 +++++- modules/notification_policy/main.tf | 58 +++++++++++++++++++ 4 files changed, 105 insertions(+), 1 deletion(-) diff --git a/examples/config/resources/notification_policies.yaml b/examples/config/resources/notification_policies.yaml index 98f141b..a351b09 100644 --- a/examples/config/resources/notification_policies.yaml +++ b/examples/config/resources/notification_policies.yaml @@ -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 diff --git a/examples/notification_policy/main.tf b/examples/notification_policy/main.tf index eb5a3be..795585b 100644 --- a/examples/notification_policy/main.tf +++ b/examples/notification_policy/main.tf @@ -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 diff --git a/modules/notification_policy/README.md b/modules/notification_policy/README.md index 4c0154f..0d2f348 100644 --- a/modules/notification_policy/README.md +++ b/modules/notification_policy/README.md @@ -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 @@ -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) diff --git a/modules/notification_policy/main.tf b/modules/notification_policy/main.tf index b08b717..312f96e 100644 --- a/modules/notification_policy/main.tf +++ b/modules/notification_policy/main.tf @@ -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)