Skip to content

Commit e507048

Browse files
authored
feat: add support to secrets manager DA solution to create event notifications destinations, topics and subscriptions (#135)
1 parent 9e18567 commit e507048

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

solutions/standard/main.tf

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,47 @@ data "ibm_resource_instance" "existing_sm" {
148148
count = var.existing_secrets_manager_crn == null ? 0 : 1
149149
identifier = var.existing_secrets_manager_crn
150150
}
151+
152+
#######################################################################################################################
153+
# Secrets Manager Event Notifications Configuration
154+
#######################################################################################################################
155+
156+
locals {
157+
parsed_existing_en_instance_crn = var.existing_event_notification_instance_crn != null ? split(":", var.existing_event_notification_instance_crn) : []
158+
existing_en_guid = length(local.parsed_existing_en_instance_crn) > 0 ? local.parsed_existing_en_instance_crn[7] : null
159+
}
160+
161+
data "ibm_en_destinations" "en_destinations" {
162+
count = var.existing_event_notification_instance_crn != null ? 1 : 0
163+
instance_guid = local.existing_en_guid
164+
}
165+
166+
resource "ibm_en_topic" "en_topic" {
167+
count = var.existing_event_notification_instance_crn != null ? 1 : 0
168+
instance_guid = local.existing_en_guid
169+
name = "Secrets Manager Topic"
170+
description = "Topic for Secrets Manager events routing"
171+
sources {
172+
id = local.secrets_manager_crn
173+
rules {
174+
enabled = true
175+
event_type_filter = "$.*"
176+
}
177+
}
178+
}
179+
180+
resource "ibm_en_subscription_email" "email_subscription" {
181+
count = var.existing_event_notification_instance_crn != null && length(var.sm_en_email_list) > 0 ? 1 : 0
182+
instance_guid = local.existing_en_guid
183+
name = "Email for Secrets Manager Subscription"
184+
description = "Subscription for Secret Manager Events"
185+
destination_id = [for s in toset(data.ibm_en_destinations.en_destinations[count.index].destinations) : s.id if s.type == "smtp_ibm"][0]
186+
topic_id = ibm_en_topic.en_topic[count.index].topic_id
187+
attributes {
188+
add_notification_payload = true
189+
reply_to_mail = var.sm_en_reply_to_email
190+
reply_to_name = "Secret Manager Event Notifications Bot"
191+
from_name = var.sm_en_from_email
192+
invited = var.sm_en_email_list
193+
}
194+
}

solutions/standard/variables.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,21 @@ variable "skip_event_notification_iam_authorization_policy" {
240240
description = "If set to true, this skips the creation of a service to service authorization from Secrets Manager to Event Notifications. If false, the service to service authorization is created."
241241
default = false
242242
}
243+
244+
variable "sm_en_email_list" {
245+
type = list(string)
246+
description = "The list of email address to target out when Secrets Manager triggers an event"
247+
default = []
248+
}
249+
250+
variable "sm_en_from_email" {
251+
type = string
252+
description = "The email address in the used in the 'from' of any Secret Manager event coming from Event Notifications"
253+
default = "compliancealert@ibm.com"
254+
}
255+
256+
variable "sm_en_reply_to_email" {
257+
type = string
258+
description = "The email address used in the 'reply_to' of any Secret Manager event coming from Event Notifications"
259+
default = "no-reply@ibm.com"
260+
}

0 commit comments

Comments
 (0)