Skip to content

Commit 2a5a804

Browse files
feat: add support for metrics bucket configuration for Cloud Logs in the instances variation (#180)
1 parent 4a3a47f commit 2a5a804

File tree

9 files changed

+136
-23
lines changed

9 files changed

+136
-23
lines changed

ibm_catalog.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,37 @@
418418
{
419419
"key": "cloud_log_data_bucket_access_tag"
420420
},
421+
{
422+
"key": "cloud_log_metrics_bucket_name"
423+
},
424+
{
425+
"key": "cloud_log_metrics_bucket_class",
426+
"options": [
427+
{
428+
"displayname": "standard",
429+
"value": "standard"
430+
},
431+
{
432+
"displayname": "vault",
433+
"value": "vault"
434+
},
435+
{
436+
"displayname": "cold",
437+
"value": "cold"
438+
},
439+
{
440+
"displayname": "smart",
441+
"value": "smart"
442+
},
443+
{
444+
"displayname": "onerate_active",
445+
"value": "onerate_active"
446+
}
447+
]
448+
},
449+
{
450+
"key": "cloud_log_metrics_bucket_access_tag"
451+
},
421452
{
422453
"key": "management_endpoint_type_for_bucket",
423454
"options": [
@@ -456,6 +487,12 @@
456487
{
457488
"key": "existing_cloud_logs_data_bucket_endpoint"
458489
},
490+
{
491+
"key": "existing_cloud_logs_metrics_bucket_crn"
492+
},
493+
{
494+
"key": "existing_cloud_logs_metrics_bucket_endpoint"
495+
},
459496
{
460497
"key": "skip_cos_kms_auth_policy"
461498
},

reference-architecture/deployable-architecture-observability-instances.svg

Lines changed: 1 addition & 1 deletion
Loading

solutions/instances/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This deployable architecture creates observability instances in IBM Cloud and su
1111
* A KMS-encrypted Object Storage bucket to store archived logs, if one is not passed in.
1212
* A KMS-encrypted Object Storage bucket for Activity Tracker event routing, if one is not passed in. (Disabled by default as service is deprecated)
1313
* A KMS-encrypted Object Storage bucket for Cloud Logs data, if one is not passed in.
14+
* A KMS-encrypted Object Storage bucket for Cloud Logs metrics, if one is not passed in.
1415
* An Activity Tracker event route to an Object Storage bucket and Cloud Logs target.
1516
* An option to integrate Cloud Logs with existing event notification instance.
1617

solutions/instances/main.tf

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ locals {
1818
at_cos_target_bucket_name = var.prefix != null ? "${var.prefix}-${var.at_cos_target_bucket_name}" : var.at_cos_target_bucket_name
1919

2020
cos_instance_crn = var.existing_cos_instance_crn != null ? var.existing_cos_instance_crn : length(module.cos_instance) != 0 ? module.cos_instance[0].cos_instance_crn : null
21-
existing_kms_guid = ((var.existing_cloud_logs_data_bucket_crn != null && var.existing_log_archive_cos_bucket_name != null && var.existing_at_cos_target_bucket_name != null) || (!var.log_analysis_provision && !var.enable_at_event_routing_to_cos_bucket && !var.cloud_logs_provision)) ? null : var.existing_kms_instance_crn != null ? element(split(":", var.existing_kms_instance_crn), length(split(":", var.existing_kms_instance_crn)) - 3) : tobool("The CRN of the existing KMS is not provided.")
21+
existing_kms_guid = ((var.existing_cloud_logs_metrics_bucket_crn != null && var.existing_cloud_logs_data_bucket_crn != null && var.existing_log_archive_cos_bucket_name != null && var.existing_at_cos_target_bucket_name != null) || (!var.log_analysis_provision && !var.enable_at_event_routing_to_cos_bucket && !var.cloud_logs_provision)) ? null : var.existing_kms_instance_crn != null ? element(split(":", var.existing_kms_instance_crn), length(split(":", var.existing_kms_instance_crn)) - 3) : tobool("The CRN of the existing KMS is not provided.")
2222
cos_instance_guid = var.existing_cos_instance_crn == null ? length(module.cos_instance) != 0 ? module.cos_instance[0].cos_instance_guid : null : element(split(":", var.existing_cos_instance_crn), length(split(":", var.existing_cos_instance_crn)) - 3)
2323
archive_cos_bucket_name = var.existing_log_archive_cos_bucket_name != null ? var.existing_log_archive_cos_bucket_name : var.log_analysis_provision ? module.cos_bucket[0].buckets[local.log_archive_cos_bucket_name].bucket_name : null
2424
archive_cos_bucket_endpoint = var.existing_log_archive_cos_bucket_endpoint != null ? var.existing_log_archive_cos_bucket_endpoint : var.log_analysis_provision ? module.cos_bucket[0].buckets[local.log_archive_cos_bucket_name].s3_endpoint_private : null
25-
cos_kms_key_crn = ((var.existing_cloud_logs_data_bucket_crn != null && var.existing_log_archive_cos_bucket_name != null && var.existing_at_cos_target_bucket_name != null) || (!var.log_analysis_provision && !var.enable_at_event_routing_to_cos_bucket && !var.cloud_logs_provision)) ? null : var.existing_cos_kms_key_crn != null ? var.existing_cos_kms_key_crn : module.kms[0].keys[format("%s.%s", local.cos_key_ring_name, local.cos_key_name)].crn
25+
cos_kms_key_crn = ((var.existing_cloud_logs_metrics_bucket_crn != null && var.existing_cloud_logs_data_bucket_crn != null && var.existing_log_archive_cos_bucket_name != null && var.existing_at_cos_target_bucket_name != null) || (!var.log_analysis_provision && !var.enable_at_event_routing_to_cos_bucket && !var.cloud_logs_provision)) ? null : var.existing_cos_kms_key_crn != null ? var.existing_cos_kms_key_crn : module.kms[0].keys[format("%s.%s", local.cos_key_ring_name, local.cos_key_name)].crn
2626

2727
cos_target_bucket_name = var.existing_at_cos_target_bucket_name != null ? var.existing_at_cos_target_bucket_name : var.enable_at_event_routing_to_cos_bucket ? module.cos_bucket[0].buckets[local.at_cos_target_bucket_name].bucket_name : null
2828
cos_target_bucket_endpoint = var.existing_at_cos_target_bucket_endpoint != null ? var.existing_at_cos_target_bucket_endpoint : var.enable_at_event_routing_to_cos_bucket ? module.cos_bucket[0].buckets[local.at_cos_target_bucket_name].s3_endpoint_private : null
@@ -51,10 +51,17 @@ locals {
5151
tag = var.cloud_log_data_bucket_access_tag
5252
} : null
5353

54+
cloud_log_metrics_bucket_config = var.existing_cloud_logs_metrics_bucket_crn == null && var.cloud_logs_provision ? {
55+
class = var.cloud_log_metrics_bucket_class
56+
name = local.cloud_log_metrics_bucket
57+
tag = var.cloud_log_metrics_bucket_access_tag
58+
} : null
59+
5460
buckets_config = concat(
5561
local.archive_bucket_config != null ? [local.archive_bucket_config] : [],
5662
local.at_bucket_config != null ? [local.at_bucket_config] : [],
57-
local.cloud_log_data_bucket_config != null ? [local.cloud_log_data_bucket_config] : []
63+
local.cloud_log_data_bucket_config != null ? [local.cloud_log_data_bucket_config] : [],
64+
local.cloud_log_metrics_bucket_config != null ? [local.cloud_log_metrics_bucket_config] : []
5865
)
5966

6067

@@ -98,11 +105,18 @@ locals {
98105

99106
apply_auth_policy = (var.skip_cos_kms_auth_policy || (length(coalesce(local.buckets_config, [])) == 0)) ? 0 : 1
100107

108+
# Cloud Logs data bucket
101109
cloud_log_data_bucket = var.prefix != null ? "${var.prefix}-${var.cloud_log_data_bucket_name}" : var.cloud_log_data_bucket_name
102110

103111
parsed_log_data_bucket_name = var.existing_cloud_logs_data_bucket_crn != null ? split(":", var.existing_cloud_logs_data_bucket_crn) : []
104112
existing_cloud_log_data_bucket_name = length(local.parsed_log_data_bucket_name) > 0 ? local.parsed_log_data_bucket_name[1] : null
105113

114+
# Cloud Logs metrics bucket
115+
cloud_log_metrics_bucket = var.prefix != null ? "${var.prefix}-${var.cloud_log_metrics_bucket_name}" : var.cloud_log_metrics_bucket_name
116+
117+
parsed_log_metrics_bucket_name = var.existing_cloud_logs_metrics_bucket_crn != null ? split(":", var.existing_cloud_logs_metrics_bucket_crn) : []
118+
existing_cloud_log_metrics_bucket_name = length(local.parsed_log_metrics_bucket_name) > 0 ? local.parsed_log_metrics_bucket_name[1] : null
119+
106120
# Event Notifications
107121
parsed_existing_en_instance_crn = var.existing_en_instance_crn != null ? split(":", var.existing_en_instance_crn) : []
108122
existing_en_guid = length(local.parsed_existing_en_instance_crn) > 0 ? local.parsed_existing_en_instance_crn[7] : null
@@ -179,9 +193,9 @@ module "observability_instance" {
179193
bucket_endpoint = var.existing_cloud_logs_data_bucket_endpoint != null ? var.existing_cloud_logs_data_bucket_endpoint : module.cos_bucket[0].buckets[local.cloud_log_data_bucket].s3_endpoint_direct
180194
},
181195
metrics_data = {
182-
enabled = false # Support tracked in https://github.com/terraform-ibm-modules/terraform-ibm-observability-da/issues/170
183-
bucket_crn = null
184-
bucket_endpoint = null
196+
enabled = true # Support of routing config is tracked in https://github.com/terraform-ibm-modules/terraform-ibm-observability-da/issues/170
197+
bucket_crn = var.existing_cloud_logs_metrics_bucket_crn != null ? var.existing_cloud_logs_metrics_bucket_crn : module.cos_bucket[0].buckets[local.cloud_log_metrics_bucket].bucket_crn
198+
bucket_endpoint = var.existing_cloud_logs_metrics_bucket_endpoint != null ? var.existing_cloud_logs_metrics_bucket_endpoint : module.cos_bucket[0].buckets[local.cloud_log_metrics_bucket].s3_endpoint_direct
185199
}
186200
} : null
187201
cloud_logs_existing_en_instances = var.existing_en_instance_crn != null ? [{

solutions/instances/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ output "cloud_log_data_bucket_name" {
9999
description = "The name of the Cloud logs data COS bucket"
100100
}
101101

102+
output "cloud_log_metrics_bucket_name" {
103+
value = var.existing_cloud_logs_metrics_bucket_crn == null && var.cloud_logs_provision ? module.cos_bucket[0].buckets[local.cloud_log_metrics_bucket].bucket_name : local.existing_cloud_log_metrics_bucket_name
104+
description = "The name of the Cloud logs metrics COS bucket"
105+
}
106+
102107
## Activity Tracker
103108
output "at_targets" {
104109
value = module.observability_instance.activity_tracker_targets

solutions/instances/variables.tf

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,42 @@ variable "cloud_log_data_bucket_access_tag" {
142142
description = "A list of optional tags to add to the cloud log data object storage bucket."
143143
}
144144

145+
variable "cloud_log_metrics_bucket_name" {
146+
type = string
147+
default = "cloud-logs-metrics-bucket"
148+
description = "The name of the Cloud Object Storage bucket to create to store cloud logs metrics. Cloud Object Storage bucket names are globally unique. If the `add_bucket_name_suffix` variable is set to `true`, 4 random characters are added to this name to ensure that the name of the bucket is globally unique. If the prefix input variable is passed, the name of the bucket is prefixed to the value in the `<prefix>-value` format."
149+
}
150+
151+
variable "existing_cloud_logs_metrics_bucket_crn" {
152+
type = string
153+
nullable = true
154+
default = null
155+
description = "The crn of an existing bucket within the Cloud Object Storage instance to store IBM Cloud Logs metrics. If an existing Cloud Object Storage bucket is not specified, a bucket is created."
156+
}
157+
158+
variable "existing_cloud_logs_metrics_bucket_endpoint" {
159+
type = string
160+
nullable = true
161+
default = null
162+
description = "The endpoint of an existing Cloud Object Storage bucket to use for storing the IBM Cloud Logs metrics. If an existing Cloud Object Storage bucket is not specified, a bucket is created."
163+
}
164+
165+
variable "cloud_log_metrics_bucket_class" {
166+
type = string
167+
default = "smart"
168+
description = "The storage class of the newly provisioned cloud logs Cloud Object Storage bucket. Specify one of the following values for the storage class: `standard`, `vault`, `cold`, `smart` (default), or `onerate_active`."
169+
validation {
170+
condition = contains(["standard", "vault", "cold", "smart", "onerate_active"], var.cloud_log_metrics_bucket_class)
171+
error_message = "Specify one of the following values for the `cos_bucket_class`: `standard`, `vault`, `cold`, `smart`, or `onerate_active`."
172+
}
173+
}
174+
175+
variable "cloud_log_metrics_bucket_access_tag" {
176+
type = list(string)
177+
default = []
178+
description = "A list of optional tags to add to the cloud log metrics object storage bucket."
179+
}
180+
145181
variable "skip_logs_routing_auth_policy" {
146182
description = "Whether to create an IAM authorization policy that permits Logs Routing Sender access to the IBM Cloud Logs."
147183
type = bool

tests/pr_test.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -261,22 +261,24 @@ func TestRunExistingResourcesInstances(t *testing.T) {
261261
ImplicitRequired: false,
262262
Region: region,
263263
TerraformVars: map[string]interface{}{
264-
"cos_region": region,
265-
"resource_group_name": terraform.Output(t, existingTerraformOptions, "resource_group_name"),
266-
"use_existing_resource_group": true,
267-
"log_analysis_provision": true,
268-
"existing_log_archive_cos_bucket_name": terraform.Output(t, existingTerraformOptions, "bucket_name"),
269-
"existing_at_cos_target_bucket_name": terraform.Output(t, existingTerraformOptions, "bucket_name_at"),
270-
"existing_log_archive_cos_bucket_endpoint": terraform.Output(t, existingTerraformOptions, "bucket_endpoint"),
271-
"existing_at_cos_target_bucket_endpoint": terraform.Output(t, existingTerraformOptions, "bucket_endpoint_at"),
272-
"existing_cos_instance_crn": terraform.Output(t, existingTerraformOptions, "cos_crn"),
273-
"existing_cloud_logs_data_bucket_crn": terraform.Output(t, existingTerraformOptions, "data_bucket_crn"),
274-
"existing_cloud_logs_data_bucket_endpoint": terraform.Output(t, existingTerraformOptions, "data_bucket_endpoint"),
275-
"existing_en_instance_crn": terraform.Output(t, existingTerraformOptions, "en_crn"),
276-
"management_endpoint_type_for_bucket": "public",
277-
"log_analysis_service_endpoints": "public",
278-
"enable_platform_metrics": "false",
279-
"enable_at_event_routing_to_log_analysis": "true",
264+
"cos_region": region,
265+
"resource_group_name": terraform.Output(t, existingTerraformOptions, "resource_group_name"),
266+
"use_existing_resource_group": true,
267+
"log_analysis_provision": true,
268+
"existing_log_archive_cos_bucket_name": terraform.Output(t, existingTerraformOptions, "bucket_name"),
269+
"existing_at_cos_target_bucket_name": terraform.Output(t, existingTerraformOptions, "bucket_name_at"),
270+
"existing_log_archive_cos_bucket_endpoint": terraform.Output(t, existingTerraformOptions, "bucket_endpoint"),
271+
"existing_at_cos_target_bucket_endpoint": terraform.Output(t, existingTerraformOptions, "bucket_endpoint_at"),
272+
"existing_cos_instance_crn": terraform.Output(t, existingTerraformOptions, "cos_crn"),
273+
"existing_cloud_logs_data_bucket_crn": terraform.Output(t, existingTerraformOptions, "data_bucket_crn"),
274+
"existing_cloud_logs_data_bucket_endpoint": terraform.Output(t, existingTerraformOptions, "data_bucket_endpoint"),
275+
"existing_cloud_logs_metrics_bucket_crn": terraform.Output(t, existingTerraformOptions, "metrics_bucket_crn"),
276+
"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_at_event_routing_to_log_analysis": "true",
280282
},
281283
})
282284

tests/resources/existing-resources/main.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ module "cloud_log_buckets" {
4747
create_cos_instance = false
4848
resource_instance_id = module.cos.cos_instance_id
4949
kms_encryption_enabled = false
50+
},
51+
{
52+
bucket_name = "${var.prefix}-metrics-bucket"
53+
add_bucket_name_suffix = true
54+
region_location = var.region
55+
create_cos_instance = false
56+
resource_instance_id = module.cos.cos_instance_id
57+
kms_encryption_enabled = false
5058
}
5159
]
5260
}

tests/resources/existing-resources/outputs.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ output "data_bucket_endpoint" {
4747
value = module.cloud_log_buckets.buckets["${var.prefix}-data-bucket"].s3_endpoint_public
4848
}
4949

50+
output "metrics_bucket_crn" {
51+
description = "Cloud Logs metrics bucket CRN"
52+
value = module.cloud_log_buckets.buckets["${var.prefix}-metrics-bucket"].bucket_crn
53+
}
54+
55+
output "metrics_bucket_endpoint" {
56+
description = "Cloud Logs metrics bucket endpoint"
57+
value = module.cloud_log_buckets.buckets["${var.prefix}-metrics-bucket"].s3_endpoint_public
58+
}
59+
5060
output "en_crn" {
5161
description = "Event Notification CRN"
5262
value = module.event_notification.crn

0 commit comments

Comments
 (0)