Skip to content

Commit ed002fa

Browse files
authored
feat: add support to send failed events to a COS bucket (#157)
1 parent a260d53 commit ed002fa

File tree

27 files changed

+543
-70
lines changed

27 files changed

+543
-70
lines changed

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ To create service credentials, access the Event Notifications service, and acces
6969
| Name | Version |
7070
|------|---------|
7171
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.0, <1.7.0 |
72-
| <a name="requirement_ibm"></a> [ibm](#requirement\_ibm) | >= 1.56.1, < 2.0.0 |
72+
| <a name="requirement_ibm"></a> [ibm](#requirement\_ibm) | >= 1.63.0, < 2.0.0 |
7373
| <a name="requirement_time"></a> [time](#requirement\_time) | >= 0.9.1 |
7474

7575
### Modules
@@ -82,18 +82,27 @@ 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 |
8586
| [ibm_en_integration.en_kms_integration](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/en_integration) | resource |
87+
| [ibm_iam_authorization_policy.cos_policy](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/iam_authorization_policy) | resource |
8688
| [ibm_iam_authorization_policy.kms_policy](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/iam_authorization_policy) | resource |
8789
| [ibm_resource_instance.en_instance](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/resource_instance) | resource |
8890
| [ibm_resource_key.service_credentials](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/resource_key) | resource |
89-
| [time_sleep.wait_for_authorization_policy](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
91+
| [time_sleep.wait_for_cos_authorization_policy](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
92+
| [time_sleep.wait_for_kms_authorization_policy](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
9093
| [ibm_en_integrations.en_integrations](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/data-sources/en_integrations) | data source |
94+
| [ibm_iam_account_settings.iam_account_settings](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/data-sources/iam_account_settings) | data source |
9195

9296
### Inputs
9397

9498
| Name | Description | Type | Default | Required |
9599
|------|-------------|------|---------|:--------:|
96100
| <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 |
101+
| <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 |
103+
| <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 |
104+
| <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 |
105+
| <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 |
97106
| <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. Required only if `var.kms_encryption_enabled` is set to `true`. | `string` | `null` | no |
98107
| <a name="input_kms_encryption_enabled"></a> [kms\_encryption\_enabled](#input\_kms\_encryption\_enabled) | Set to `true` to control the encryption keys that are used to encrypt the data that you store in the Event Notifications instance. If set to `false`, the data is encrypted by using randomly generated keys. For more information, see [Managing encryption](https://cloud.ibm.com/docs/event-notifications?topic=event-notifications-en-managing-encryption). | `bool` | `false` | no |
99108
| <a name="input_kms_endpoint_url"></a> [kms\_endpoint\_url](#input\_kms\_endpoint\_url) | The URL of the KMS endpoint to use when configuring KMS encryption. The Hyper Protect Crypto Services endpoint URL format is `https://api.private.<REGION>.hs-crypto.cloud.ibm.com:<port>` and the Key Protect endpoint URL format is `https://<REGION>.kms.cloud.ibm.com`. | `string` | `null` | no |
@@ -104,7 +113,8 @@ To create service credentials, access the Event Notifications service, and acces
104113
| <a name="input_root_key_id"></a> [root\_key\_id](#input\_root\_key\_id) | The key ID of a root key, existing in the KMS instance passed in `var.existing_kms_instance_crn`, which will be used to encrypt the data encryption keys which are then used to encrypt the data. Required only if `var.kms_encryption_enabled` is set to `true`. | `string` | `null` | no |
105114
| <a name="input_service_credential_names"></a> [service\_credential\_names](#input\_service\_credential\_names) | The mapping of names and roles for service credentials that you want to create for the Event Notifications instance. | `map(string)` | `{}` | no |
106115
| <a name="input_service_endpoints"></a> [service\_endpoints](#input\_service\_endpoints) | Specify whether you want to enable public, or both public and private service endpoints. Possible values: `public`, `public-and-private` | `string` | `"public-and-private"` | no |
107-
| <a name="input_skip_iam_authorization_policy"></a> [skip\_iam\_authorization\_policy](#input\_skip\_iam\_authorization\_policy) | Set to `true` to skip the creation of an IAM authorization policy that permits all Event Notifications instances in the resource group to read the encryption key from the KMS instance. If set to `false`, specify a value for the KMS instance in the `existing_kms_instance_guid` variable. In addition, no policy is created if `kms_encryption_enabled` is set to `false`. | `bool` | `false` | no |
116+
| <a name="input_skip_en_cos_auth_policy"></a> [skip\_en\_cos\_auth\_policy](#input\_skip\_en\_cos\_auth\_policy) | Whether an IAM authorization policy is created for your Event Notifications instance to interact with your Object Storage bucket. Set to `true` to use an existing policy. Ignored if `cos_integration_enabled` is set to `false`. | `bool` | `false` | no |
117+
| <a name="input_skip_en_kms_auth_policy"></a> [skip\_en\_kms\_auth\_policy](#input\_skip\_en\_kms\_auth\_policy) | Set to `true` to skip the creation of an IAM authorization policy that permits all Event Notifications instances in the resource group to read the encryption key from the KMS instance. If set to `false`, specify a value for the KMS instance in the `existing_kms_instance_guid` variable. In addition, no policy is created if `kms_encryption_enabled` is set to `false`. | `bool` | `false` | no |
108118
| <a name="input_tags"></a> [tags](#input\_tags) | The list of tags to add to the Event Notifications instance. | `list(string)` | `[]` | no |
109119

110120
### Outputs

cra-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ CRA_TARGETS:
88
TF_VAR_resource_group_name: "test"
99
TF_VAR_existing_kms_instance_crn: "crn:v1:bluemix:public:hs-crypto:us-south:a/abac0df06b644a9cabc6e44f55b3880e:e6dce284-e80f-46e1-a3c1-830f7adff7a9::"
1010
TF_VAR_kms_endpoint_url: "https://api.private.us-south.hs-crypto.cloud.ibm.com:8992"
11+
TF_VAR_cross_region_location: "us"

cra-tf-validate-ignore-rules.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
{
2-
"scc_rules": []
2+
"scc_rules": [
3+
{
4+
"scc_rule_id": "rule-8cbd597c-7471-42bd-9c88-36b2696456e9",
5+
"description": "Check whether Cloud Object Storage network access is restricted to a specific IP range",
6+
"ignore_reason": "Tracked at https://github.com/terraform-ibm-modules/terraform-ibm-event-notifications/issues/161",
7+
"is_valid": true
8+
}
9+
]
310
}

examples/basic/main.tf

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ module "resource_group" {
1515
##############################################################################
1616

1717
module "event_notification" {
18-
source = "../../"
19-
resource_group_id = module.resource_group.resource_group_id
20-
name = "${var.prefix}-en"
21-
tags = var.resource_tags
22-
plan = "lite"
23-
service_endpoints = "public"
24-
region = var.region
18+
source = "../../"
19+
resource_group_id = module.resource_group.resource_group_id
20+
name = "${var.prefix}-en"
21+
tags = var.resource_tags
22+
plan = "lite"
23+
service_endpoints = "public"
24+
region = var.region
25+
cos_integration_enabled = false
2526
}

examples/basic/version.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ terraform {
66
required_providers {
77
ibm = {
88
source = "IBM-Cloud/ibm"
9-
version = "1.56.1"
9+
version = "1.63.0"
1010
}
1111
}
1212
}

examples/complete/README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# Complete example with BYOK encryption and CBR rules
22

3-
An end-to-end example that does the following:
3+
An end-to-end example that creates the following infrastructure:
44

5-
- Create a new resource group if one is not passed in.
6-
- Create Key Protect instance with root key.
7-
- Create a new Event Notification instance with BYOK encryption.
8-
- Create a Virtual Private Cloud (VPC).
9-
- Create a context-based restriction (CBR) rule to only allow Event Notification to be accessible from within the VPC.
10-
- Create a service credentials for the Event Notification instance.
5+
- A resource group, if one is not passed in.
6+
- A Key Protect instance with a root key.
7+
- An Event Notifications instance with bring-your-own-key encryption.
8+
- An IBM Cloud Object Storage service instance and bucket to collect events that fail delivery.
9+
- A Virtual Private Cloud (VPC).
10+
- A context-based restriction (CBR) rule to allow Event Notifications to be accessible only from within the VPC.
11+
- Service credentials for the Event Notifications instance.

examples/complete/main.tf

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ locals {
1818
key_ring_name = "en-key-ring"
1919
key_name = "${var.prefix}-en"
2020
}
21+
2122
module "key_protect_all_inclusive" {
2223
source = "terraform-ibm-modules/key-protect-all-inclusive/ibm"
2324
version = "4.8.5"
@@ -33,6 +34,26 @@ module "key_protect_all_inclusive" {
3334
}]
3435
}
3536

37+
##############################################################################
38+
# Create Cloud Object Storage instance and a bucket
39+
##############################################################################
40+
41+
locals {
42+
bucket_name = "${var.prefix}-bucket"
43+
}
44+
45+
module "cos" {
46+
source = "terraform-ibm-modules/cos/ibm"
47+
version = "7.5.0"
48+
resource_group_id = module.resource_group.resource_group_id
49+
region = var.region
50+
cos_instance_name = "${var.prefix}-cos"
51+
cos_tags = var.resource_tags
52+
bucket_name = local.bucket_name
53+
retention_enabled = false # disable retention for test environments - enable for stage/prod
54+
kms_encryption_enabled = false
55+
}
56+
3657
##############################################################################
3758
# Get Cloud Account ID
3859
##############################################################################
@@ -85,6 +106,12 @@ module "event_notification" {
85106
service_endpoints = "public"
86107
service_credential_names = var.service_credential_names
87108
region = var.region
109+
# COS Related
110+
cos_integration_enabled = true
111+
cos_destination_name = module.cos.cos_instance_name
112+
cos_bucket_name = module.cos.bucket_name
113+
cos_instance_id = module.cos.cos_instance_guid
114+
cos_endpoint = "https://${module.cos.s3_endpoint_public}"
88115
cbr_rules = [
89116
{
90117
description = "${var.prefix}-event notification access only from vpc"

examples/complete/version.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ terraform {
66
required_providers {
77
ibm = {
88
source = "IBM-Cloud/ibm"
9-
version = ">= 1.49.0, < 2.0.0"
9+
version = ">= 1.63.0, < 2.0.0"
1010
}
1111
}
1212
}

examples/fscloud/main.tf

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,49 @@ module "cbr_zone" {
5050
}]
5151
}
5252

53+
##############################################################################
54+
# Create COS Instance
55+
##############################################################################
56+
57+
locals {
58+
bucket_name = "cos-bucket"
59+
kms_instance_guid = element(split(":", var.existing_kms_instance_crn), length(split(":", var.existing_kms_instance_crn)) - 3)
60+
root_key_id = element(split(":", var.root_key_crn), length(split(":", var.root_key_crn)) - 1)
61+
}
62+
63+
module "cos" {
64+
source = "terraform-ibm-modules/cos/ibm//modules/fscloud"
65+
version = "7.5.0"
66+
resource_group_id = module.resource_group.resource_group_id
67+
create_cos_instance = true
68+
create_resource_key = false
69+
cos_instance_name = "${var.prefix}-cos"
70+
cos_plan = "standard"
71+
bucket_configs = [{
72+
access_tags = []
73+
add_bucket_name_suffix = true
74+
bucket_name = local.bucket_name
75+
kms_encryption_enabled = true
76+
kms_guid = local.kms_instance_guid
77+
kms_key_crn = var.root_key_crn
78+
skip_iam_authorization_policy = false
79+
management_endpoint_type = "public"
80+
storage_class = "smart"
81+
region_location = var.region
82+
force_delete = true
83+
}]
84+
}
85+
86+
##############################################################################
87+
# Create Event Notifications Instance
88+
##############################################################################
89+
5390
module "event_notification" {
5491
source = "../../modules/fscloud"
5592
resource_group_id = module.resource_group.resource_group_id
5693
name = "${var.prefix}-en-fs"
5794
existing_kms_instance_crn = var.existing_kms_instance_crn
58-
root_key_id = var.root_key_id
95+
root_key_id = local.root_key_id
5996
kms_endpoint_url = var.kms_endpoint_url
6097
tags = var.resource_tags
6198

@@ -73,6 +110,11 @@ module "event_notification" {
73110
"en_custom_email_status_reporter" : "Custom Email Status Reporter",
74111
}
75112
region = var.region
113+
# COS Related
114+
cos_bucket_name = module.cos.buckets[local.bucket_name].bucket_name
115+
cos_instance_id = module.cos.cos_instance_guid
116+
skip_en_cos_auth_policy = false
117+
cos_endpoint = "https://${module.cos.buckets[local.bucket_name].s3_endpoint_private}"
76118
cbr_rules = [
77119
{
78120
description = "${var.prefix}-event notification access only from vpc"

0 commit comments

Comments
 (0)