Skip to content

Commit 382b00f

Browse files
authored
feat: add the ability to continue managing the log archiving bucket even after log archiving has been disabled or logdna has been deleted (#183)
1 parent 70a0338 commit 382b00f

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

solutions/instances/main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ locals {
2020
at_cos_target_bucket_name = var.prefix != null ? "${var.prefix}-${var.at_cos_target_bucket_name}" : var.at_cos_target_bucket_name
2121

2222
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
23-
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.")
23+
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.manage_log_archive_cos_bucket && !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.")
2424
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)
25-
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
26-
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+
archive_cos_bucket_name = var.existing_log_archive_cos_bucket_name != null ? var.existing_log_archive_cos_bucket_name : (var.log_analysis_provision && var.log_analysis_enable_archive) || var.manage_log_archive_cos_bucket ? module.cos_bucket[0].buckets[local.log_archive_cos_bucket_name].bucket_name : null
26+
archive_cos_bucket_endpoint = var.existing_log_archive_cos_bucket_endpoint != null ? var.existing_log_archive_cos_bucket_endpoint : (var.log_analysis_provision && var.log_analysis_enable_archive) || var.manage_log_archive_cos_bucket ? module.cos_bucket[0].buckets[local.log_archive_cos_bucket_name].s3_endpoint_private : null
2727
cos_kms_key_crn = var.existing_cos_kms_key_crn != null ? var.existing_cos_kms_key_crn : length(coalesce(local.buckets_config, [])) != 0 ? module.kms[0].keys[format("%s.%s", local.cos_key_ring_name, local.cos_key_name)].crn : null
2828

2929
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
@@ -36,7 +36,7 @@ locals {
3636
at_log_analysis_route_name = var.prefix != null ? "${var.prefix}-at-log-analysis-route" : "at-log-analysis-route"
3737
at_cloud_logs_route_name = var.prefix != null ? "${var.prefix}-at-cloud-logs-route" : "at-cloud-logs-route"
3838

39-
archive_bucket_config = var.existing_log_archive_cos_bucket_name == null && var.log_analysis_provision ? {
39+
archive_bucket_config = var.existing_log_archive_cos_bucket_name == null && ((var.log_analysis_provision && var.log_analysis_enable_archive) || var.manage_log_archive_cos_bucket) ? {
4040
class = var.log_archive_cos_bucket_class
4141
name = local.log_archive_cos_bucket_name
4242
tag = var.archive_bucket_access_tags

solutions/instances/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ output "cos_instance_crn" {
8585

8686
## COS Buckets
8787
output "log_archive_cos_bucket_name" {
88-
value = var.existing_log_archive_cos_bucket_name == null ? var.log_analysis_provision ? module.cos_bucket[0].buckets[local.log_archive_cos_bucket_name].bucket_name : null : var.existing_log_archive_cos_bucket_name
88+
value = var.existing_log_archive_cos_bucket_name == null ? (var.log_analysis_provision && var.log_analysis_enable_archive) || var.manage_log_archive_cos_bucket ? module.cos_bucket[0].buckets[local.log_archive_cos_bucket_name].bucket_name : null : var.existing_log_archive_cos_bucket_name
8989
description = "The name of log archive COS bucket"
9090
}
9191

solutions/instances/variables.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ variable "prefix" {
6060
##############################################################################
6161
# IBM Cloud Logs
6262
##############################################################################
63+
6364
variable "cloud_logs_provision" {
6465
description = "Set it to true to provision an IBM Cloud Logs instance"
6566
type = bool
@@ -267,6 +268,12 @@ variable "log_archive_api_key" {
267268
default = null
268269
}
269270

271+
variable "manage_log_archive_cos_bucket" {
272+
type = bool
273+
default = false
274+
description = "Log Analysis has been deprecated, however you can continue to manage the COS bucket that was used for Log Analysis log archiving by setting this input to true, even if `log_analysis_provision` or `log_analysis_enable_archive` have been set to false."
275+
}
276+
270277
##############################################################################
271278
# Activity Tracker Event Routing Variables
272279
##############################################################################

tests/pr_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ func TestRunExistingResourcesInstances(t *testing.T) {
278278
"management_endpoint_type_for_bucket": "public",
279279
"log_analysis_service_endpoints": "public",
280280
"enable_platform_metrics": "false",
281+
"enable_platform_logs": "false",
281282
"enable_at_event_routing_to_log_analysis": "true",
282283
},
283284
})

0 commit comments

Comments
 (0)