Skip to content

Commit 5bc846d

Browse files
authored
feat: add support to use existing cloud monitoring instance with new input variable existing_cloud_monitoring_crn (#91)
1 parent cffbb2e commit 5bc846d

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

ibm_catalog.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@
224224
{
225225
"key": "cloud_monitoring_provision"
226226
},
227+
{
228+
"key": "existing_cloud_monitoring_crn"
229+
},
227230
{
228231
"key": "cloud_monitoring_instance_name"
229232
},

solutions/instances/main.tf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ locals {
66

77
# tflint-ignore: terraform_unused_declarations
88
validate_log_analysis_provision = var.enable_at_event_routing_to_log_analysis && var.log_analysis_provision == false ? tobool("log_analysis_provision can't be false if enable_at_event_routing_to_log_analysis is true") : true
9+
# tflint-ignore: terraform_unused_declarations
10+
validate_existing_cloud_monitoring = var.cloud_monitoring_provision && var.existing_cloud_monitoring_crn != null ? tobool("if cloud_monitoring_provision is set to true, then existing_cloud_monitoring_crn should be null and vice versa") : true
911

1012
archive_api_key = var.log_archive_api_key == null ? var.ibmcloud_api_key : var.log_archive_api_key
1113
default_cos_region = var.cos_region != null ? var.cos_region : var.region
@@ -25,10 +27,10 @@ locals {
2527
cos_target_bucket_name = var.existing_at_cos_target_bucket_name != null ? var.existing_at_cos_target_bucket_name : module.cos_bucket[0].buckets[local.at_cos_target_bucket_name].bucket_name
2628
cos_target_bucket_endpoint = var.existing_at_cos_target_bucket_endpoint != null ? var.existing_at_cos_target_bucket_endpoint : module.cos_bucket[0].buckets[local.at_cos_target_bucket_name].s3_endpoint_private
2729

28-
metrics_monitoring = var.cloud_monitoring_provision ? {
30+
metrics_monitoring = var.cloud_monitoring_provision || (var.existing_cloud_monitoring_crn != null) ? {
2931
usage_metrics_enabled = true
3032
request_metrics_enabled = true
31-
metrics_monitoring_crn = module.observability_instance.cloud_monitoring_crn
33+
metrics_monitoring_crn = var.cloud_monitoring_provision ? module.observability_instance.cloud_monitoring_crn : var.existing_cloud_monitoring_crn
3234
} : null
3335

3436
bucket_config_1 = var.existing_log_archive_cos_bucket_name == null && var.log_analysis_provision == true ? {
@@ -152,7 +154,6 @@ module "observability_instance" {
152154

153155
# Routes
154156
activity_tracker_routes = local.at_routes
155-
156157
}
157158

158159
#######################################################################################################################

solutions/instances/variables.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,17 @@ variable "enable_at_event_routing_to_log_analysis" {
118118
##############################################################################
119119

120120
variable "cloud_monitoring_provision" {
121-
description = "Set it to true to provision an IBM cloud monitoring instance"
121+
description = "Whether to create an IBM cloud monitoring instance. Set to `false` if a CRN is specified in `existing_cloud_monitoring_crn`."
122122
type = bool
123123
default = true
124124
}
125125

126+
variable "existing_cloud_monitoring_crn" {
127+
description = "The CRN of an IBM Cloud Monitoring instance. If specified, set the `cloud_monitoring_provision` variable to `false`."
128+
type = string
129+
default = null
130+
}
131+
126132
variable "cloud_monitoring_instance_name" {
127133
type = string
128134
description = "The name of the IBM Cloud Monitoring instance to create. If prefix input variable is passed then it will get prefixed infront of the value in the format of '<prefix>-value'"

0 commit comments

Comments
 (0)