Skip to content

Commit d03e2a5

Browse files
authored
feat: The module was incorrectly creating a COS destination instead of creating a COS integration needed for failed events to work. Due to this change, the cos_destination_name has been removed. If you are updating from a previous version, you will see the expected destroy of the destination (#242)
1 parent 50d21db commit d03e2a5

File tree

12 files changed

+104
-83
lines changed

12 files changed

+104
-83
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ To create service credentials, access the Event Notifications service, and acces
8282

8383
| Name | Type |
8484
|------|------|
85-
| [ibm_en_destination_cos.cos_en_destination](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/en_destination_cos) | resource |
8685
| [ibm_en_integration.en_kms_integration](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/en_integration) | resource |
86+
| [ibm_en_integration_cos.en_cos_integration](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/en_integration_cos) | resource |
8787
| [ibm_iam_authorization_policy.cos_policy](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/iam_authorization_policy) | resource |
8888
| [ibm_iam_authorization_policy.kms_policy](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/iam_authorization_policy) | resource |
8989
| [ibm_resource_instance.en_instance](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/resource_instance) | resource |
@@ -99,7 +99,6 @@ To create service credentials, access the Event Notifications service, and acces
9999
|------|-------------|------|---------|:--------:|
100100
| <a name="input_cbr_rules"></a> [cbr\_rules](#input\_cbr\_rules) | The list of context-based restrictions rules to create. | <pre>list(object({<br> description = string<br> account_id = string<br> rule_contexts = list(object({<br> attributes = optional(list(object({<br> name = string<br> value = string<br> }))) }))<br> enforcement_mode = string<br> }))</pre> | `[]` | no |
101101
| <a name="input_cos_bucket_name"></a> [cos\_bucket\_name](#input\_cos\_bucket\_name) | The name of an existing IBM Cloud Object Storage bucket which will be used for storage of failed delivery events. Required if `cos_integration_enabled` is set to true. | `string` | `null` | no |
102-
| <a name="input_cos_destination_name"></a> [cos\_destination\_name](#input\_cos\_destination\_name) | The name of the IBM Cloud Object Storage destination which will be created for the storage of failed delivery events. | `string` | `"COS Destination"` | no |
103102
| <a name="input_cos_endpoint"></a> [cos\_endpoint](#input\_cos\_endpoint) | The endpoint URL for your bucket region. For more information, see https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-endpoints. Required if `cos_integration_enabled` is set to true. | `string` | `null` | no |
104103
| <a name="input_cos_instance_id"></a> [cos\_instance\_id](#input\_cos\_instance\_id) | The ID of the IBM Cloud Object Storage instance in which the bucket that is defined in the `cos_bucket_name` variable exists. Required if `cos_integration_enabled` is set to true. | `string` | `null` | no |
105104
| <a name="input_cos_integration_enabled"></a> [cos\_integration\_enabled](#input\_cos\_integration\_enabled) | Set to `true` to connect a Cloud Object Storage service instance to your Event Notifications instance to collect events that failed delivery. If set to false, no failed events will be captured. | `bool` | `false` | no |

examples/complete/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ An end-to-end example that creates the following infrastructure:
77
- An Event Notifications instance with bring-your-own-key encryption.
88
- An IBM Cloud Object Storage service instance and bucket to collect events that fail delivery.
99
- A Virtual Private Cloud (VPC).
10-
- A context-based restriction (CBR) rule to allow Event Notifications to be accessible only from within the VPC.
10+
- A context-based restriction (CBR) rule to allow Event Notifications to be accessible from VPC and Schematics.
1111
- Service credentials for the Event Notifications instance.

examples/complete/main.tf

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ module "cbr_zone_schematics" {
111111
}]
112112
}
113113

114+
#############################################################################
115+
# Create EN instance, destination, topic and subscription
116+
##############################################################################
117+
114118
module "event_notification" {
115119
source = "../../"
116120
resource_group_id = module.resource_group.resource_group_id
@@ -125,9 +129,8 @@ module "event_notification" {
125129
region = var.region
126130
# COS Related
127131
cos_integration_enabled = true
128-
cos_destination_name = module.cos.cos_instance_name
129132
cos_bucket_name = module.cos.bucket_name
130-
cos_instance_id = module.cos.cos_instance_guid
133+
cos_instance_id = module.cos.cos_instance_crn
131134
cos_endpoint = "https://${module.cos.s3_endpoint_public}"
132135
cbr_rules = [
133136
{
@@ -158,3 +161,38 @@ module "event_notification" {
158161
}
159162
]
160163
}
164+
165+
resource "ibm_en_destination_webhook" "webhook_destination" {
166+
instance_guid = module.event_notification.guid
167+
name = "${var.prefix}-webhook-destination"
168+
type = "webhook"
169+
collect_failed_events = false
170+
description = "Destination webhook for event notification"
171+
config {
172+
params {
173+
verb = "POST"
174+
url = "https://testwebhook.com"
175+
custom_headers = {
176+
"authorization" = "authorization"
177+
}
178+
sensitive_headers = ["authorization"]
179+
}
180+
}
181+
}
182+
183+
resource "ibm_en_topic" "webhook_topic" {
184+
instance_guid = module.event_notification.guid
185+
name = "${var.prefix}-e2e-topic"
186+
description = "Topic for EN events routing"
187+
}
188+
189+
resource "ibm_en_subscription_webhook" "webhook_subscription" {
190+
instance_guid = module.event_notification.guid
191+
name = "${var.prefix}-webhook-subscription"
192+
description = "The webhook subscription"
193+
destination_id = ibm_en_destination_webhook.webhook_destination.destination_id
194+
topic_id = ibm_en_topic.webhook_topic.topic_id
195+
attributes {
196+
signing_enabled = true
197+
}
198+
}

examples/fscloud/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The example uses the IBM Cloud Terraform provider to create the following infras
88
- An IAM authorization between all Event Notification instances in the given resource group and the KMS instance that is passed in.
99
- An Event Notification instance that is encrypted with the KMS root key that is passed in.
1010
- A sample virtual private cloud (VPC).
11-
- A context-based restriction (CBR) rule to only allow Event Notification to be accessible from within the VPC.
11+
- A context-based restriction (CBR) rule to only allow Event Notification to be accessible from VPC and Schematics.
1212

1313
:exclamation: **Important:** In this example, only the Event Notification instance complies with the IBM Cloud Framework for Financial Services. Other parts of the infrastructure do not necessarily comply.
1414

examples/fscloud/main.tf

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ module "cos" {
9090
kms_guid = local.kms_instance_guid
9191
kms_key_crn = var.root_key_crn
9292
skip_iam_authorization_policy = false
93-
management_endpoint_type = "public"
93+
management_endpoint_type = "private"
9494
storage_class = "smart"
9595
region_location = var.region
9696
force_delete = true
@@ -126,35 +126,38 @@ module "event_notification" {
126126
region = var.region
127127
# COS Related
128128
cos_bucket_name = module.cos.buckets[local.bucket_name].bucket_name
129-
cos_instance_id = module.cos.cos_instance_guid
129+
cos_instance_id = module.cos.cos_instance_crn
130130
skip_en_cos_auth_policy = false
131131
cos_endpoint = "https://${module.cos.buckets[local.bucket_name].s3_endpoint_private}"
132-
cbr_rules = [
133-
{
134-
description = "${var.prefix}-event notification access only from vpc"
135-
enforcement_mode = "enabled"
136-
account_id = data.ibm_iam_account_settings.iam_account_settings.account_id
137-
rule_contexts = [{
138-
attributes = [
139-
{
140-
"name" : "endpointType",
141-
"value" : "private"
142-
},
143-
{
144-
name = "networkZoneId"
145-
value = module.cbr_vpc_zone.zone_id
146-
}]
147-
}, {
148-
attributes = [
149-
{
150-
"name" : "endpointType",
151-
"value" : "private"
152-
},
153-
{
154-
name = "networkZoneId"
155-
value = module.cbr_zone_schematics.zone_id
156-
}]
157-
}]
158-
}
159-
]
132+
133+
# There is a known issue https://github.com/IBM-Cloud/terraform-provider-ibm/issues/5525 when adding schematics network zone with private endpoint type to the EN CBR rule, causing this example to fail.
134+
135+
# cbr_rules = [
136+
# {
137+
# description = "${var.prefix}-event notification access from vpc and schematics"
138+
# enforcement_mode = "enabled"
139+
# account_id = data.ibm_iam_account_settings.iam_account_settings.account_id
140+
# rule_contexts = [{
141+
# attributes = [
142+
# {
143+
# "name" : "endpointType",
144+
# "value" : "private"
145+
# },
146+
# {
147+
# name = "networkZoneId"
148+
# value = module.cbr_vpc_zone.zone_id
149+
# }]
150+
# }, {
151+
# attributes = [
152+
# {
153+
# "name" : "endpointType",
154+
# "value" : "private"
155+
# },
156+
# {
157+
# name = "networkZoneId"
158+
# value = module.cbr_zone_schematics.zone_id
159+
# }]
160+
# }]
161+
# }
162+
# ]
160163
}

main.tf

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ locals {
88
validate_kms_values = !var.kms_encryption_enabled && (var.existing_kms_instance_crn != null || var.root_key_id != null || var.kms_endpoint_url != null) ? tobool("When passing values for var.existing_kms_instance_crn or/and var.root_key_id or/and var.kms_endpoint_url, you must set var.kms_encryption_enabled to true. Otherwise unset them to use default encryption") : true
99
# tflint-ignore: terraform_unused_declarations
1010
validate_kms_vars = var.kms_encryption_enabled && (var.existing_kms_instance_crn == null || var.root_key_id == null || var.kms_endpoint_url == null) ? tobool("When setting var.kms_encryption_enabled to true, a value must be passed for var.existing_kms_instance_crn, var.root_key_id and var.kms_endpoint_url") : true
11+
# tflint-ignore: terraform_unused_declarations
12+
validate_cos_values = !var.cos_integration_enabled && (var.cos_instance_id != null || var.cos_bucket_name != null || var.cos_endpoint != null) ? tobool("When passing values for var.cos_instance_id or/and var.cos_bucket_name or/and var.cos_endpoint, you must set var.cos_integration_enabled to true. Otherwise unset them to disable collection of failed delivery events") : true
13+
# tflint-ignore: terraform_unused_declarations
14+
validate_cos_vars = var.cos_integration_enabled && (var.cos_instance_id == null || var.cos_bucket_name == null || var.cos_endpoint == null) ? tobool("When setting var.cos_integration_enabled to true, a value must be passed for var.cos_instance_id, var.cos_bucket_name and var.cos_endpoint") : true
1115

1216
# Determine what KMS service is being used for encryption
1317
kms_service = var.existing_kms_instance_crn != null ? (
@@ -31,23 +35,17 @@ resource "ibm_resource_instance" "en_instance" {
3135
}
3236

3337
#############################################################################
34-
# Event Notification COS integration
38+
# Event Notification COS integration to Collect Failed Events
3539
#############################################################################
36-
37-
resource "ibm_en_destination_cos" "cos_en_destination" {
38-
depends_on = [time_sleep.wait_for_cos_authorization_policy]
39-
count = var.cos_integration_enabled ? 1 : 0
40-
instance_guid = ibm_resource_instance.en_instance.guid
41-
name = var.cos_destination_name
42-
type = "ibmcos"
43-
collect_failed_events = true
44-
description = "IBM Cloud Object Storage destination for collection of failed events."
45-
config {
46-
params {
47-
bucket_name = var.cos_bucket_name
48-
instance_id = var.cos_instance_id
49-
endpoint = var.cos_endpoint
50-
}
40+
resource "ibm_en_integration_cos" "en_cos_integration" {
41+
depends_on = [time_sleep.wait_for_cos_authorization_policy]
42+
count = var.cos_integration_enabled ? 1 : 0
43+
instance_guid = ibm_resource_instance.en_instance.guid
44+
type = "collect_failed_events"
45+
metadata {
46+
endpoint = var.cos_endpoint
47+
crn = var.cos_instance_id
48+
bucket_name = var.cos_bucket_name
5149
}
5250
}
5351

@@ -56,7 +54,11 @@ resource "ibm_en_destination_cos" "cos_en_destination" {
5654
#############################################################################
5755

5856
locals {
59-
en_integration_id = length(data.ibm_en_integrations.en_integrations) > 0 ? data.ibm_en_integrations.en_integrations[0].integrations[0]["id"] : null
57+
58+
en_integration_id = length(data.ibm_en_integrations.en_integrations) > 0 ? [
59+
for integrations in data.ibm_en_integrations.en_integrations[0].integrations :
60+
integrations.id if(integrations.type == "kms" || integrations.type == "hs-crypto")
61+
] : null
6062
}
6163

6264
data "ibm_en_integrations" "en_integrations" {
@@ -68,7 +70,7 @@ resource "ibm_en_integration" "en_kms_integration" {
6870
depends_on = [time_sleep.wait_for_kms_authorization_policy]
6971
count = var.kms_encryption_enabled == false ? 0 : 1
7072
instance_guid = ibm_resource_instance.en_instance.guid
71-
integration_id = local.en_integration_id
73+
integration_id = local.en_integration_id[0]
7274
type = local.kms_service
7375
metadata {
7476
endpoint = var.kms_endpoint_url
@@ -90,6 +92,7 @@ data "ibm_iam_account_settings" "iam_account_settings" {
9092

9193
locals {
9294
existing_kms_instance_guid = var.kms_encryption_enabled == true ? element(split(":", var.existing_kms_instance_crn), length(split(":", var.existing_kms_instance_crn)) - 3) : null
95+
existing_cos_instance_guid = var.cos_integration_enabled == true ? element(split(":", var.cos_instance_id), length(split(":", var.cos_instance_id)) - 3) : null
9396
}
9497

9598
# Create IAM Authorization Policies to allow event notification to access cos
@@ -98,7 +101,7 @@ resource "ibm_iam_authorization_policy" "cos_policy" {
98101
source_service_name = "event-notifications"
99102
source_resource_instance_id = ibm_resource_instance.en_instance.guid
100103
roles = ["Object Writer", "Reader"]
101-
description = "Allow EN instance with GUID ${ibm_resource_instance.en_instance.guid} `Object Writer` and `Reader` access to the COS instance with ID ${var.cos_instance_id}."
104+
description = "Allow EN instance with GUID ${ibm_resource_instance.en_instance.guid} `Object Writer` and `Reader` access to the COS instance with GUID ${local.existing_cos_instance_guid}."
102105

103106
resource_attributes {
104107
name = "serviceName"
@@ -114,7 +117,7 @@ resource "ibm_iam_authorization_policy" "cos_policy" {
114117
resource_attributes {
115118
name = "serviceInstance"
116119
operator = "stringEquals"
117-
value = var.cos_instance_id
120+
value = local.existing_cos_instance_guid
118121
}
119122

120123
resource_attributes {

modules/fscloud/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,9 @@ No resources.
8282
|------|-------------|------|---------|:--------:|
8383
| <a name="input_cbr_rules"></a> [cbr\_rules](#input\_cbr\_rules) | The list of context-based restrictions rules to create. | <pre>list(object({<br> description = string<br> account_id = string<br> rule_contexts = list(object({<br> attributes = optional(list(object({<br> name = string<br> value = string<br> }))) }))<br> enforcement_mode = string<br> }))</pre> | `[]` | no |
8484
| <a name="input_cos_bucket_name"></a> [cos\_bucket\_name](#input\_cos\_bucket\_name) | The name of an existing Object Storage bucket to use for the storage of failed delivery events. | `string` | `null` | no |
85-
| <a name="input_cos_destination_name"></a> [cos\_destination\_name](#input\_cos\_destination\_name) | The name of the IBM Cloud Object Storage destination which will be created for the storage of failed delivery events. | `string` | `"COS Destination"` | no |
8685
| <a name="input_cos_endpoint"></a> [cos\_endpoint](#input\_cos\_endpoint) | The endpoint URL for your bucket region. Required if `cos_integration_enabled` is set to `true`. [Learn more](https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-endpoints). | `string` | `null` | no |
87-
| <a name="input_cos_instance_id"></a> [cos\_instance\_id](#input\_cos\_instance\_id) | The ID of the Object Storage instance that contains the bucket that is specified in the `cos_bucket_name` variable. Required only if `cos_integration_enabled` is set to `true`. | `string` | `null` | no |
88-
| <a name="input_cos_integration_enabled"></a> [cos\_integration\_enabled](#input\_cos\_integration\_enabled) | Whether to connect an Object Storage service instance to your Event Notifications instance to collect events that fail delivery. If set to `false`, no failed events are captured. | `bool` | `true` | no |
86+
| <a name="input_cos_instance_id"></a> [cos\_instance\_id](#input\_cos\_instance\_id) | The ID of the IBM Cloud Object Storage instance in which the bucket that is defined in the `cos_bucket_name` variable exists. Required if `cos_integration_enabled` is set to true. | `string` | `null` | no |
87+
| <a name="input_cos_integration_enabled"></a> [cos\_integration\_enabled](#input\_cos\_integration\_enabled) | Whether to connect an Object Storage service instance to your Event Notifications instance to collect events that failed delivery. If set to `false`, no failed events are captured. | `bool` | `true` | no |
8988
| <a name="input_existing_kms_instance_crn"></a> [existing\_kms\_instance\_crn](#input\_existing\_kms\_instance\_crn) | The CRN of the Hyper Protect Crypto Services or Key Protect instance. To ensure compliance with IBM Cloud Framework for Financial Services standards, it is required to use Hyper Protect Crypto Services only. | `string` | n/a | yes |
9089
| <a name="input_kms_endpoint_url"></a> [kms\_endpoint\_url](#input\_kms\_endpoint\_url) | The KMS endpoint URL to use when you configure KMS encryption. | `string` | n/a | yes |
9190
| <a name="input_name"></a> [name](#input\_name) | The name of the Event Notifications instance that is created by this module. | `string` | n/a | yes |

modules/fscloud/main.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ module "event_notification" {
1616
# COS Related
1717
cos_integration_enabled = var.cos_integration_enabled
1818
cos_endpoint = var.cos_endpoint
19-
cos_destination_name = var.cos_destination_name
2019
cos_bucket_name = var.cos_bucket_name
2120
cos_instance_id = var.cos_instance_id
2221
skip_en_cos_auth_policy = var.skip_en_cos_auth_policy

modules/fscloud/variables.tf

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,6 @@ variable "cbr_rules" {
7070
# COS
7171
########################################################################################################################
7272

73-
variable "cos_destination_name" {
74-
type = string
75-
description = "The name of the IBM Cloud Object Storage destination which will be created for the storage of failed delivery events."
76-
default = "COS Destination"
77-
}
78-
7973
variable "cos_bucket_name" {
8074
type = string
8175
description = "The name of an existing Object Storage bucket to use for the storage of failed delivery events."
@@ -84,7 +78,7 @@ variable "cos_bucket_name" {
8478

8579
variable "cos_instance_id" {
8680
type = string
87-
description = "The ID of the Object Storage instance that contains the bucket that is specified in the `cos_bucket_name` variable. Required only if `cos_integration_enabled` is set to `true`."
81+
description = "The ID of the IBM Cloud Object Storage instance in which the bucket that is defined in the `cos_bucket_name` variable exists. Required if `cos_integration_enabled` is set to true."
8882
default = null
8983
}
9084

@@ -96,7 +90,7 @@ variable "skip_en_cos_auth_policy" {
9690

9791
variable "cos_integration_enabled" {
9892
type = bool
99-
description = "Whether to connect an Object Storage service instance to your Event Notifications instance to collect events that fail delivery. If set to `false`, no failed events are captured."
93+
description = "Whether to connect an Object Storage service instance to your Event Notifications instance to collect events that failed delivery. If set to `false`, no failed events are captured."
10094
default = true
10195
}
10296

0 commit comments

Comments
 (0)