add email & notification topics

This commit is contained in:
bdeshi 2024-05-28 03:44:48 +06:00
parent 47b2e4d7dc
commit c5c5dc3e4b
Signed by: bdeshi
GPG Key ID: 410D03DA9A3468E0
6 changed files with 68 additions and 16 deletions

View File

@ -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 : {}

View File

@ -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
}

View File

@ -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
} }
})
}

View File

@ -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
}

View File

@ -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

View File

@ -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 = {}
}