From c5c5dc3e4b8e4adabcabb6e0935beb5deb03ffa2 Mon Sep 17 00:00:00 2001 From: bdeshi Date: Tue, 28 May 2024 03:44:48 +0600 Subject: [PATCH] add email & notification topics --- oci.data.tf | 4 ++++ oci.email.tf | 21 +++++++++++++++++++++ oci.locals.tf | 8 ++++++++ oci.notification.tf | 17 +++++++++++++++++ terraform.outputs.tf | 8 ++++++++ terraform.variables.tf | 26 ++++++++++---------------- 6 files changed, 68 insertions(+), 16 deletions(-) diff --git a/oci.data.tf b/oci.data.tf index 20166f6..8dba773 100644 --- a/oci.data.tf +++ b/oci.data.tf @@ -2,6 +2,10 @@ data "oci_identity_tenancy" "tenancy" { tenancy_id = var.tenancy_id } +data "oci_email_configuration" "endpoints" { + compartment_id = var.tenancy_id +} + # use this instead of oci_kms_key.key to await supporting policy creation data "oci_kms_key" "key" { for_each = var.create_vault ? var.use_kms : {} diff --git a/oci.email.tf b/oci.email.tf index e69de29..d01dbae 100644 --- a/oci.email.tf +++ b/oci.email.tf @@ -0,0 +1,21 @@ +resource "oci_email_email_domain" "domain" { + for_each = toset(var.enable_email_delivery ? var.email_configuration.email_domains : []) + compartment_id = oci_identity_compartment.compartment.id + name = each.value + freeform_tags = local.freeform_tags +} + +resource "oci_email_sender" "sender" { + for_each = toset(var.enable_email_delivery ? var.email_configuration.approved_senders : []) + + compartment_id = oci_identity_compartment.compartment.id + email_address = each.value + freeform_tags = local.freeform_tags +} + +resource "oci_email_suppression" "suppression" { + for_each = toset(var.enable_email_delivery ? var.email_configuration.suppression_list : []) + + compartment_id = oci_identity_compartment.compartment.id + email_address = each.value +} diff --git a/oci.locals.tf b/oci.locals.tf index 3114b99..ab6bcee 100644 --- a/oci.locals.tf +++ b/oci.locals.tf @@ -49,4 +49,12 @@ locals { index = split("_", item)[1] } } + + topic_subscriptions = values({ for k, v in var.topics : + k => { for i, s in v.subscriptions : "${k}_${i}" => { + topic = k + protocol = s.protocol + endpoint = s.endpoint + } } + }) } diff --git a/oci.notification.tf b/oci.notification.tf index e69de29..0052804 100644 --- a/oci.notification.tf +++ b/oci.notification.tf @@ -0,0 +1,17 @@ +resource "oci_ons_notification_topic" "topic" { + for_each = var.create_topics ? var.topics : {} + compartment_id = oci_identity_compartment.compartment.id + name = each.key + description = try(each.value.description, null) + freeform_tags = local.freeform_tags +} + +resource "oci_ons_subscription" "subscription" { + for_each = var.create_topics ? local.topic_subscriptions : toset([]) + + compartment_id = oci_identity_compartment.compartment.id + topic_id = oci_ons_notification_topic.topic[each.value.topic].id + protocol = each.value.protocol + endpoint = each.value.endpoint + freeform_tags = local.freeform_tags +} diff --git a/terraform.outputs.tf b/terraform.outputs.tf index c7bd5fd..e80d3d8 100644 --- a/terraform.outputs.tf +++ b/terraform.outputs.tf @@ -113,6 +113,14 @@ output "instance_selected_images" { value = { for k, v in data.oci_core_images.selected : k => v.images[0].display_name } } +output "email_endpoints" { + description = "The email configuration endpoints" + value = { + http = data.oci_email_configuration.endpoints.http_submit_endpoint + smtp = data.oci_email_configuration.endpoints.smtp_submit_endpoint + } +} + output "kms_vault_id" { description = "The ID of the KMS vault" value = oci_kms_vault.vault[0].id diff --git a/terraform.variables.tf b/terraform.variables.tf index bed22d9..4fc4b47 100644 --- a/terraform.variables.tf +++ b/terraform.variables.tf @@ -158,26 +158,20 @@ variable "email_configuration" { } } -variable "create_notification_topics" { +variable "create_topics" { description = "Create notification topics" type = bool default = true } -variable "topic_configuration" { +variable "topics" { description = "Values for notification topics configuration" - type = any - default = {} -} - -variable "enable_object_storage" { - description = "Create object storage bucket supporting configuration" - type = bool - default = true -} - -variable "object_storage_buckets" { - description = "Values for object storage buckets to create" - type = any - default = {} + type = map(object({ + description = string + subscriptions = list(object({ + protocol = string + endpoint = string + })) + })) + default = {} }