Skip to content
This repository was archived by the owner on Mar 19, 2025. It is now read-only.

Commit e2e3659

Browse files
authored
feat: added support to create Event Notifications destinations, topics and subscriptions (#99)
1 parent 520c40a commit e2e3659

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

solutions/instances/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ This solution supports the following:
3333

3434
| Name | Type |
3535
|------|------|
36+
| [ibm_en_subscription_email.email_subscription](https://registry.terraform.io/providers/IBM-Cloud/ibm/1.66.0/docs/resources/en_subscription_email) | resource |
37+
| [ibm_en_topic.en_topic](https://registry.terraform.io/providers/IBM-Cloud/ibm/1.66.0/docs/resources/en_topic) | resource |
38+
| [ibm_en_destinations.en_destinations](https://registry.terraform.io/providers/IBM-Cloud/ibm/1.66.0/docs/data-sources/en_destinations) | data source |
3639
| [ibm_iam_account_settings.iam_account_settings](https://registry.terraform.io/providers/IBM-Cloud/ibm/1.66.0/docs/data-sources/iam_account_settings) | data source |
3740

3841
### Inputs
@@ -63,6 +66,9 @@ This solution supports the following:
6366
| <a name="input_scc_cos_bucket_name"></a> [scc\_cos\_bucket\_name](#input\_scc\_cos\_bucket\_name) | The name to use when creating the SCC Cloud Object Storage bucket (NOTE: bucket names are globally unique). If 'add\_bucket\_name\_suffix' is set to true, a random 4 characters will be added to this name to help ensure bucket name is globally unique. If prefix input variable is passed then it will get prefixed infront of the value in the format of '<prefix>-value'. | `string` | `"base-security-services-bucket"` | no |
6467
| <a name="input_scc_cos_key_name"></a> [scc\_cos\_key\_name](#input\_scc\_cos\_key\_name) | The name to give the Key which will be created for the SCC COS bucket. Not used if supplying an existing Key. If prefix input variable is passed then it will get prefixed infront of the value in the format of '<prefix>-value'. | `string` | `"scc-cos-key"` | no |
6568
| <a name="input_scc_cos_key_ring_name"></a> [scc\_cos\_key\_ring\_name](#input\_scc\_cos\_key\_ring\_name) | The name to give the Key Ring which will be created for the SCC COS bucket Key. Not used if supplying an existing Key. If prefix input variable is passed then it will get prefixed infront of the value in the format of '<prefix>-value'. | `string` | `"scc-cos-key-ring"` | no |
69+
| <a name="input_scc_en_email_list"></a> [scc\_en\_email\_list](#input\_scc\_en\_email\_list) | The list of email address to target out when Security and Compliance Center triggers an event | `list(string)` | `[]` | no |
70+
| <a name="input_scc_en_from_email"></a> [scc\_en\_from\_email](#input\_scc\_en\_from\_email) | The email address in the used in the 'from' of any Security and Compliance Center event coming from Event Notifications | `string` | `"[email protected]"` | no |
71+
| <a name="input_scc_en_reply_to_email"></a> [scc\_en\_reply\_to\_email](#input\_scc\_en\_reply\_to\_email) | The email address used in the 'reply\_to' of any Security and Compliance Center event coming from Event Notifications | `string` | `"[email protected]"` | no |
6672
| <a name="input_scc_instance_name"></a> [scc\_instance\_name](#input\_scc\_instance\_name) | The name to give the SCC instance that will be provisioned by this solution. If prefix input variable is passed then it will get prefixed infront of the value in the format of '<prefix>-value'. | `string` | `"base-security-services-scc"` | no |
6773
| <a name="input_scc_instance_tags"></a> [scc\_instance\_tags](#input\_scc\_instance\_tags) | Optional list of tags to be added to SCC instance. | `list(string)` | `[]` | no |
6874
| <a name="input_scc_region"></a> [scc\_region](#input\_scc\_region) | The region in which to provision SCC resources. | `string` | `"us-south"` | no |

solutions/instances/main.tf

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,47 @@ module "scc_wp" {
202202
access_tags = var.scc_workload_protection_access_tags
203203
scc_wp_service_plan = var.scc_workload_protection_service_plan
204204
}
205+
206+
#######################################################################################################################
207+
# SCC Event Notifications Configuration
208+
#######################################################################################################################
209+
210+
locals {
211+
parsed_existing_en_instance_crn = var.existing_en_crn != null ? split(":", var.existing_en_crn) : []
212+
existing_en_guid = length(local.parsed_existing_en_instance_crn) > 0 ? local.parsed_existing_en_instance_crn[7] : null
213+
}
214+
215+
data "ibm_en_destinations" "en_destinations" {
216+
count = var.existing_en_crn != null ? 1 : 0
217+
instance_guid = local.existing_en_guid
218+
}
219+
220+
resource "ibm_en_topic" "en_topic" {
221+
count = var.existing_en_crn != null ? 1 : 0
222+
instance_guid = local.existing_en_guid
223+
name = "SCC Topic"
224+
description = "Topic for SCC events routing"
225+
sources {
226+
id = module.scc.crn
227+
rules {
228+
enabled = true
229+
event_type_filter = "$.*"
230+
}
231+
}
232+
}
233+
234+
resource "ibm_en_subscription_email" "email_subscription" {
235+
count = var.existing_en_crn != null && length(var.scc_en_email_list) > 0 ? 1 : 0
236+
instance_guid = local.existing_en_guid
237+
name = "Email for Security and Compliance Center Subscription"
238+
description = "Subscription for Security and Compliance Center Events"
239+
destination_id = [for s in toset(data.ibm_en_destinations.en_destinations[count.index].destinations) : s.id if s.type == "smtp_ibm"][0]
240+
topic_id = ibm_en_topic.en_topic[count.index].topic_id
241+
attributes {
242+
add_notification_payload = true
243+
reply_to_mail = var.scc_en_reply_to_email
244+
reply_to_name = "SCC Event Notifications Bot"
245+
from_name = var.scc_en_from_email
246+
invited = var.scc_en_email_list
247+
}
248+
}

solutions/instances/variables.tf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,25 @@ variable "scc_workload_protection_access_tags" {
273273
error_message = "Tags must match the regular expression \"[\\w\\-_\\.]+:[\\w\\-_\\.]+\", see https://cloud.ibm.com/docs/account?topic=account-tag&interface=ui#limits for more details"
274274
}
275275
}
276+
277+
########################################################################################################################
278+
# EN Configuration variables
279+
########################################################################################################################
280+
281+
variable "scc_en_from_email" {
282+
type = string
283+
description = "The email address in the used in the 'from' of any Security and Compliance Center event coming from Event Notifications"
284+
default = "[email protected]"
285+
}
286+
287+
variable "scc_en_reply_to_email" {
288+
type = string
289+
description = "The email address used in the 'reply_to' of any Security and Compliance Center event coming from Event Notifications"
290+
default = "[email protected]"
291+
}
292+
293+
variable "scc_en_email_list" {
294+
type = list(string)
295+
description = "The list of email address to target out when Security and Compliance Center triggers an event"
296+
default = []
297+
}

0 commit comments

Comments
 (0)