Skip to content

Commit 8be90a0

Browse files
authored
feat: support to pass multiple Event Notifications instances to Observability DA. [Learn more](https://github.com/terraform-ibm-modules/terraform-ibm-observability-da/blob/main/solutions/instances/DA-types.md) (#177)
1 parent 382b00f commit 8be90a0

File tree

7 files changed

+103
-25
lines changed

7 files changed

+103
-25
lines changed

ibm_catalog.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@
210210
{
211211
"key": "logs_routing_tenant_regions"
212212
},
213+
{
214+
"key": "cloud_logs_existing_en_instances"
215+
},
213216
{
214217
"key": "existing_en_instance_crn"
215218
},

solutions/instances/DA-types.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Configuring Event Notification (EN) Instances for Cloud Logging
2+
3+
An optional input variables in the IBM Cloud [Observability instances deployable architecture](https://cloud.ibm.com/catalog#deployable_architecture) use complex object types. You specify these inputs when you configure deployable architecture.
4+
5+
- [Cloud Logs Event Notification Instances](#cloud_logs_existing_en_instances) (`cloud_logs_existing_en_instances`)
6+
7+
## Cloud Logs Event Notification Instances <a name="cloud_logs_existing_en_instances"></a>
8+
9+
The `cloud_logs_existing_en_instances` input variable allows you to provide a list of existing Event Notification (EN) instances that will be integrated with the Cloud Logging service. For each EN instance, you need to specify its CRN (Cloud Resource Name). You can also optionally configure a integration name and control whether to skip the creation of an authentication policy for the instance.
10+
11+
- Variable name: `cloud_logs_existing_en_instances`.
12+
- Type: A list of objects. Each object represents an EN instance with the following attributes:
13+
- `instance_crn` (required): The Cloud Resource Name (CRN) of the Event Notification instance.
14+
- `integration_name` (optional): The name of the Event Notification integration that gets created. If a prefix input variable is passed, it is prefixed to the value in the `<prefix>-value` format. Defaults to `"cloud-logs-en-integration"`.
15+
- `skip_en_auth_policy` (optional): A boolean flag to determine whether to skip the creation of an authentication policy that allows Cloud Logs 'Event Source Manager' role access in the existing event notification instance. Defaults to `false`.
16+
- Default value: An empty list (`[]`).
17+
18+
19+
### Example Event Notification Instance Configuration
20+
21+
```hcl
22+
cloud_logs_existing_en_instances = [
23+
{
24+
instance_crn = "crn:v1:bluemix:public:...:event-notifications:instance"
25+
integration_name = "custom-logging-en-integration"
26+
skip_en_auth_policy = true
27+
},
28+
{
29+
instance_crn = "crn:v1:bluemix:public:...:event-notifications:instance"
30+
skip_en_auth_policy = false
31+
}
32+
]
33+
```
34+
35+
In this example:
36+
- The first EN instance has a integration name `"custom-logging-en-integration"` and skips the authentication policy.
37+
- The second EN instance uses the default integration name and includes the authentication policy.

solutions/instances/main.tf

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,12 @@ locals {
119119
parsed_log_metrics_bucket_name = var.existing_cloud_logs_metrics_bucket_crn != null ? split(":", var.existing_cloud_logs_metrics_bucket_crn) : []
120120
existing_cloud_log_metrics_bucket_name = length(local.parsed_log_metrics_bucket_name) > 0 ? local.parsed_log_metrics_bucket_name[1] : null
121121

122-
# Event Notifications
123-
parsed_existing_en_instance_crn = var.existing_en_instance_crn != null ? split(":", var.existing_en_instance_crn) : []
124-
existing_en_guid = length(local.parsed_existing_en_instance_crn) > 0 ? local.parsed_existing_en_instance_crn[7] : null
125-
en_region = length(local.parsed_existing_en_instance_crn) > 0 ? local.parsed_existing_en_instance_crn[5] : null
126-
en_integration_name = var.prefix != null ? "${var.prefix}-${var.en_integration_name}" : var.en_integration_name
127-
122+
# https://github.ibm.com/GoldenEye/issues/issues/10928#issuecomment-93550079
123+
cloud_logs_existing_en_instances = concat(var.cloud_logs_existing_en_instances, var.existing_en_instance_crn != null ? [{
124+
instance_crn = var.existing_en_instance_crn
125+
integration_name = var.en_integration_name
126+
skip_en_auth_policy = var.skip_en_auth_policy
127+
}] : [])
128128
}
129129

130130
#######################################################################################################################
@@ -206,6 +206,13 @@ resource "ibm_iam_authorization_policy" "cos_policy" {
206206
}
207207
}
208208

209+
module "en_crn_parser" {
210+
count = length(local.cloud_logs_existing_en_instances)
211+
source = "terraform-ibm-modules/common-utilities/ibm//modules/crn-parser"
212+
version = "1.0.0"
213+
crn = local.cloud_logs_existing_en_instances[count.index]["instance_crn"]
214+
}
215+
209216
module "observability_instance" {
210217
depends_on = [time_sleep.wait_for_atracker_cos_authorization_policy]
211218
source = "terraform-ibm-modules/observability-instances/ibm"
@@ -258,12 +265,12 @@ module "observability_instance" {
258265
skip_cos_auth_policy = var.ibmcloud_cos_api_key != null ? true : var.skip_cloud_logs_cos_auth_policy
259266
}
260267
} : null
261-
cloud_logs_existing_en_instances = var.existing_en_instance_crn != null ? [{
262-
en_instance_id = local.existing_en_guid
263-
en_region = local.en_region
264-
en_instance_name = local.en_integration_name
265-
skip_en_auth_policy = var.skip_en_auth_policy
266-
}] : []
268+
cloud_logs_existing_en_instances = [for index, _ in local.cloud_logs_existing_en_instances : {
269+
en_instance_id = module.en_crn_parser[index]["service_instance"]
270+
en_region = module.en_crn_parser[index]["region"]
271+
en_integration_name = var.prefix != null ? "${var.prefix}-${local.cloud_logs_existing_en_instances[index]["integration_name"]}" : local.cloud_logs_existing_en_instances[index]["integration_name"]
272+
skip_en_auth_policy = local.cloud_logs_existing_en_instances[index]["skip_en_auth_policy"]
273+
}]
267274
skip_logs_routing_auth_policy = var.skip_logs_routing_auth_policy
268275
logs_routing_tenant_regions = var.logs_routing_tenant_regions
269276

solutions/instances/variables.tf

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,22 +91,32 @@ variable "cloud_logs_access_tags" {
9191
error_message = "Tags must match the regular expression \"[\\w\\-_\\.]+:[\\w\\-_\\.]+\". For more information, see https://cloud.ibm.com/docs/account?topic=account-tag&interface=ui#limits."
9292
}
9393
}
94+
# https://github.ibm.com/GoldenEye/issues/issues/10928#issuecomment-93550079
95+
variable "cloud_logs_existing_en_instances" {
96+
description = "A list of existing Event Notification instances to be integrated with the Cloud Logging service. Each object in the list represents an Event Notification instance, including its CRN, an optional name for the integration, and an optional flag to skip the authentication policy creation for the Event Notification instance [Learn more](https://github.com/terraform-ibm-modules/terraform-ibm-observability-da/tree/main/solutions/standard/DA-types.md#cloud_logs_existing_en_instances). This variable is intended for integrating a multiple Event Notifications instance to Cloud Logs. If you need to integrate only one instance, you may also use the `existing_en_instance_crn`, `en_integration_name` and `skip_en_auth_policy` variables instead."
97+
type = list(object({
98+
instance_crn = string
99+
integration_name = optional(string, "cloud-logs-en-integration")
100+
skip_en_auth_policy = optional(bool, false)
101+
}))
102+
default = []
103+
}
94104

95105
variable "existing_en_instance_crn" {
96106
type = string
97-
description = "The CRN of the existing event notification instance. If a value is provided here, `enable_en_cloud_logs_integration` must be set to true in order to enable the integration."
107+
description = "The CRN of the existing event notification instance. This variable is intended for integrating a single Event Notifications instance to Cloud Logs. If you need to integrate multiple instances, use the `cloud_logs_existing_en_instances` variable instead."
98108
default = null
99109
}
100110

101111
variable "en_integration_name" {
102112
type = string
103-
description = "The name of the event notification integration that gets created. If a prefix input variable is passed, it is prefixed to the value in the `<prefix>-value` format."
113+
description = "The name of the event notification integration that gets created. If a prefix input variable is passed, it is prefixed to the value in the `<prefix>-value` format. This variable is intended for integrating a single Event Notifications instance to Cloud Logs. If you need to integrate multiple instances, use the `cloud_logs_existing_en_instances` variable instead."
104114
default = "cloud-logs-en-integration"
105115
}
106116

107117
variable "skip_en_auth_policy" {
108118
type = bool
109-
description = "To skip creating auth policy that allows Cloud Logs 'Event Source Manager' role access in the existing event notification instance."
119+
description = "To skip creating auth policy that allows Cloud Logs 'Event Source Manager' role access in the existing event notification instance. This variable is intended for integrating a single Event Notifications instance to Cloud Logs. If you need to integrate multiple instances, use the `cloud_logs_existing_en_instances` variable instead."
110120
default = false
111121
}
112122

tests/pr_test.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,17 @@ func TestRunExistingResourcesInstances(t *testing.T) {
274274
"existing_cloud_logs_data_bucket_endpoint": terraform.Output(t, existingTerraformOptions, "data_bucket_endpoint"),
275275
"existing_cloud_logs_metrics_bucket_crn": terraform.Output(t, existingTerraformOptions, "metrics_bucket_crn"),
276276
"existing_cloud_logs_metrics_bucket_endpoint": terraform.Output(t, existingTerraformOptions, "metrics_bucket_endpoint"),
277-
"existing_en_instance_crn": terraform.Output(t, existingTerraformOptions, "en_crn"),
278-
"management_endpoint_type_for_bucket": "public",
279-
"log_analysis_service_endpoints": "public",
280-
"enable_platform_metrics": "false",
281-
"enable_platform_logs": "false",
282-
"enable_at_event_routing_to_log_analysis": "true",
277+
"existing_en_instance_crn": terraform.Output(t, existingTerraformOptions, "en_crn_1"),
278+
"cloud_logs_existing_en_instances": []map[string]interface{}{
279+
{
280+
"instance_crn": terraform.Output(t, existingTerraformOptions, "en_crn_2"),
281+
},
282+
},
283+
"management_endpoint_type_for_bucket": "public",
284+
"log_analysis_service_endpoints": "public",
285+
"enable_platform_metrics": "false",
286+
"enable_at_event_routing_to_log_analysis": "true",
287+
"enable_platform_logs": "false",
283288
},
284289
})
285290

tests/resources/existing-resources/main.tf

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,22 @@ module "cloud_log_buckets" {
6363
# Event Notification
6464
##############################################################################
6565

66-
module "event_notification" {
66+
module "event_notification_1" {
6767
source = "terraform-ibm-modules/event-notifications/ibm"
6868
version = "1.6.5"
6969
resource_group_id = module.resource_group.resource_group_id
70-
name = "${var.prefix}-en"
70+
name = "${var.prefix}-en-1"
71+
tags = var.resource_tags
72+
plan = "standard"
73+
service_endpoints = "public"
74+
region = var.region
75+
}
76+
77+
module "event_notification_2" {
78+
source = "terraform-ibm-modules/event-notifications/ibm"
79+
version = "1.6.5"
80+
resource_group_id = module.resource_group.resource_group_id
81+
name = "${var.prefix}-en-2"
7182
tags = var.resource_tags
7283
plan = "standard"
7384
service_endpoints = "public"

tests/resources/existing-resources/outputs.tf

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ output "metrics_bucket_endpoint" {
5757
value = module.cloud_log_buckets.buckets["${var.prefix}-metrics-bucket"].s3_endpoint_public
5858
}
5959

60-
output "en_crn" {
60+
output "en_crn_1" {
6161
description = "Event Notification CRN"
62-
value = module.event_notification.crn
62+
value = module.event_notification_1.crn
63+
}
64+
65+
output "en_crn_2" {
66+
description = "Event Notification CRN"
67+
value = module.event_notification_2.crn
6368
}

0 commit comments

Comments
 (0)