Skip to content

Commit 817437b

Browse files
authored
feat: add optional prefix variable to the DA solution (#216)
1 parent d386fdd commit 817437b

File tree

2 files changed

+34
-22
lines changed

2 files changed

+34
-22
lines changed

solutions/standard/main.tf

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
module "resource_group" {
66
source = "terraform-ibm-modules/resource-group/ibm"
77
version = "1.1.6"
8-
resource_group_name = var.use_existing_resource_group == false ? var.resource_group_name : null
8+
resource_group_name = var.use_existing_resource_group == false ? (var.prefix != null ? "${var.prefix}-${var.resource_group_name}" : var.resource_group_name) : null
99
existing_resource_group_name = var.use_existing_resource_group == true ? var.resource_group_name : null
1010
}
1111

@@ -20,6 +20,10 @@ locals {
2020
kms_region = length(local.parsed_existing_kms_instance_crn) > 0 ? local.parsed_existing_kms_instance_crn[5] : null
2121
en_kms_key_id = local.existing_kms_root_key_id != null ? local.existing_kms_root_key_id : module.kms[0].keys[format("%s.%s", var.en_key_ring_name, var.en_key_name)].key_id
2222
kms_instance_guid = var.existing_kms_instance_crn != null ? element(split(":", var.existing_kms_instance_crn), length(split(":", var.existing_kms_instance_crn)) - 3) : module.kms[0].kms_instance_guid
23+
en_key_name = var.prefix != null ? "${var.prefix}-${var.en_key_name}" : var.en_key_name
24+
en_key_ring_name = var.prefix != null ? "${var.prefix}-${var.en_key_ring_name}" : var.en_key_ring_name
25+
cos_key_name = var.prefix != null ? "${var.prefix}-${var.cos_key_name}" : var.cos_key_name
26+
cos_key_ring_name = var.prefix != null ? "${var.prefix}-${var.cos_key_ring_name}" : var.cos_key_ring_name
2327
}
2428

2529
# KMS root key for Event Notifications
@@ -37,12 +41,12 @@ module "kms" {
3741
key_endpoint_type = var.kms_endpoint_type
3842
keys = [
3943
{
40-
key_ring_name = var.en_key_ring_name
44+
key_ring_name = local.en_key_ring_name
4145
existing_key_ring = false
4246
force_delete_key_ring = true
4347
keys = [
4448
{
45-
key_name = var.en_key_name
49+
key_name = local.en_key_name
4650
standard_key = false
4751
rotation_interval_month = 3
4852
dual_auth_delete_enabled = false
@@ -51,12 +55,12 @@ module "kms" {
5155
]
5256
},
5357
{
54-
key_ring_name = var.cos_key_ring_name
58+
key_ring_name = local.cos_key_ring_name
5559
existing_key_ring = false
5660
force_delete_key_ring = true
5761
keys = [
5862
{
59-
key_name = var.cos_key_name
63+
key_name = local.cos_key_name
6064
standard_key = false
6165
rotation_interval_month = 3
6266
dual_auth_delete_enabled = false
@@ -73,11 +77,13 @@ module "kms" {
7377

7478
locals {
7579
# tflint-ignore: terraform_unused_declarations
76-
validate_cos_regions = var.cos_bucket_region != null && var.cross_region_location != null ? tobool("Cannot provide values for var.cos_bucket_region and var.cross_region_location") : true
77-
cos_kms_key_crn = var.existing_cos_bucket_name != null ? null : var.existing_kms_root_key_crn != null ? var.existing_kms_root_key_crn : module.kms[0].keys[format("%s.%s", var.cos_key_ring_name, var.cos_key_name)].crn
78-
cos_instance_guid = var.existing_cos_instance_crn != null ? element(split(":", var.existing_cos_instance_crn), length(split(":", var.existing_cos_instance_crn)) - 3) : module.cos.cos_instance_guid
79-
cos_bucket_name = var.existing_cos_bucket_name != null ? var.existing_cos_bucket_name : module.cos.bucket_name
80-
cos_bucket_region = var.cos_bucket_region != null ? var.cos_bucket_region : var.cross_region_location != null ? null : var.region
80+
validate_cos_regions = var.cos_bucket_region != null && var.cross_region_location != null ? tobool("Cannot provide values for var.cos_bucket_region and var.cross_region_location") : true
81+
cos_kms_key_crn = var.existing_cos_bucket_name != null ? null : local.existing_kms_root_key_id != null ? local.existing_kms_root_key_id : module.kms[0].keys[format("%s.%s", var.cos_key_ring_name, var.cos_key_name)].crn
82+
cos_instance_guid = var.existing_cos_instance_crn != null ? element(split(":", var.existing_cos_instance_crn), length(split(":", var.existing_cos_instance_crn)) - 3) : module.cos.cos_instance_guid
83+
cos_bucket_name = var.existing_cos_bucket_name != null ? var.existing_cos_bucket_name : (var.prefix != null ? "${var.prefix}-${var.cos_bucket_name}" : var.cos_bucket_name)
84+
cos_bucket_name_with_suffix = var.existing_cos_bucket_name != null ? var.existing_cos_bucket_name : module.cos.bucket_name
85+
cos_bucket_region = var.cos_bucket_region != null ? var.cos_bucket_region : var.cross_region_location != null ? null : var.region
86+
cos_instance_name = var.prefix != null ? "${var.prefix}-${var.cos_instance_name}" : var.cos_instance_name
8187
}
8288

8389
module "cos" {
@@ -91,10 +97,10 @@ module "cos" {
9197
resource_group_id = module.resource_group.resource_group_id
9298
region = local.cos_bucket_region
9399
cross_region_location = var.cross_region_location
94-
cos_instance_name = var.cos_instance_name
100+
cos_instance_name = local.cos_instance_name
95101
cos_plan = var.cos_plan
96102
cos_tags = var.cos_instance_tags
97-
bucket_name = var.cos_bucket_name
103+
bucket_name = local.cos_bucket_name
98104
access_tags = var.cos_instance_access_tags
99105
management_endpoint_type_for_bucket = var.management_endpoint_type_for_bucket
100106
existing_kms_instance_guid = local.kms_instance_guid
@@ -120,7 +126,7 @@ module "event_notifications" {
120126
source = "../.."
121127
resource_group_id = module.resource_group.resource_group_id
122128
region = var.region
123-
name = var.event_notification_name
129+
name = var.prefix != null ? "${var.prefix}-${var.event_notification_name}" : var.event_notification_name
124130
plan = var.service_plan
125131
tags = var.tags
126132
service_endpoints = var.service_endpoints
@@ -134,7 +140,7 @@ module "event_notifications" {
134140
# COS Related
135141
cos_integration_enabled = true
136142
cos_destination_name = var.cos_destination_name
137-
cos_bucket_name = local.cos_bucket_name
143+
cos_bucket_name = local.cos_bucket_name_with_suffix
138144
cos_instance_id = local.cos_instance_guid
139145
skip_en_cos_auth_policy = var.skip_en_cos_auth_policy
140146
cos_endpoint = local.cos_endpoint

solutions/standard/variables.tf

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ variable "use_existing_resource_group" {
1616

1717
variable "resource_group_name" {
1818
type = string
19-
description = "The name of a new or an existing resource group in which Event Notifications resources are provisioned."
19+
description = "The name of a new or an existing resource group in which to provision the Databases for Elasicsearch in. If a `prefix` input variable is specified, it is added to this name in the `<prefix>-value` format."
2020
}
2121

2222
variable "region" {
@@ -32,6 +32,12 @@ variable "existing_monitoring_crn" {
3232
description = "(Optional) The CRN of an existing IBM Cloud Monitoring instance. It is used to monitor the IBM Cloud Object Storage bucket that is used for storing failed events."
3333
}
3434

35+
variable "prefix" {
36+
type = string
37+
description = "(Optional) Prefix to add to all resources created by this solution."
38+
default = null
39+
}
40+
3541
########################################################################################################################
3642
# Event Notifications
3743
########################################################################################################################
@@ -49,7 +55,7 @@ variable "service_credential_names" {
4955

5056
variable "event_notification_name" {
5157
type = string
52-
description = "The name of the Event Notifications instance that is created by this solution."
58+
description = "The name of the Event Notifications instance that is created by this solution. If a `prefix` input variable is specified, it is added to this name in the `<prefix>-value` format."
5359
default = "base-event-notifications"
5460
}
5561

@@ -113,25 +119,25 @@ variable "kms_endpoint_type" {
113119
variable "en_key_ring_name" {
114120
type = string
115121
default = "en-key-ring"
116-
description = "The name of the key ring which will be created for the Event Notifications instance. Not used if supplying an existing key."
122+
description = "The name of the key ring which will be created for the Event Notifications instance. Not used if supplying an existing key. If a `prefix` input variable is specified, it is added to this name in the `<prefix>-value` format."
117123
}
118124

119125
variable "en_key_name" {
120126
type = string
121127
default = "en-key"
122-
description = "The name for the key that will be created for the Event Notifications. Not used if an existing key is specfied."
128+
description = "The name for the key that will be created for the Event Notifications. Not used if an existing key is specfied. If a `prefix` input variable is specified, it is added to this name in the `<prefix>-value` format."
123129
}
124130

125131
variable "cos_key_ring_name" {
126132
type = string
127133
default = "en-cos-key-ring"
128-
description = "The name of the key ring which will be created for Object Storage. Not used if supplying an existing key or if `existing_cos_bucket_name` is specified."
134+
description = "The name of the key ring which will be created for Object Storage. Not used if supplying an existing key or if `existing_cos_bucket_name` is specified. If a `prefix` input variable is specified, it is added to this name in the `<prefix>-value` format."
129135
}
130136

131137
variable "cos_key_name" {
132138
type = string
133139
default = "en-cos-key"
134-
description = "The name of the key which will be created for the Event Notifications. Not used if supplying an existing key."
140+
description = "The name of the key which will be created for the Event Notifications. Not used if supplying an existing key. If a `prefix` input variable is specified, it is added to this name in the `<prefix>-value` format."
135141
}
136142

137143
variable "skip_en_kms_auth_policy" {
@@ -166,7 +172,7 @@ variable "cos_destination_name" {
166172

167173
variable "cos_bucket_name" {
168174
type = string
169-
description = "The name to use when creating the Object Storage bucket for the storage of failed delivery events. Bucket names are globally unique. If `add_bucket_name_suffix` is set to `true`, a random 4 character string is added to this name to help ensure that the bucket name is unique."
175+
description = "The name to use when creating the Object Storage bucket for the storage of failed delivery events. Bucket names are globally unique. If `add_bucket_name_suffix` is set to `true`, a random 4 character string is added to this name to help ensure that the bucket name is unique. If a `prefix` input variable is specified, it is added to this name in the `<prefix>-value` format."
170176
default = "base-event-notifications-bucket"
171177
}
172178

@@ -185,7 +191,7 @@ variable "skip_cos_kms_auth_policy" {
185191
variable "cos_instance_name" {
186192
type = string
187193
default = "base-security-services-cos"
188-
description = "The name to use when creating the Object Storage instance."
194+
description = "The name to use when creating the Object Storage instance. If a `prefix` input variable is specified, it is added to this name in the `<prefix>-value` format."
189195
}
190196

191197
variable "cos_instance_tags" {

0 commit comments

Comments
 (0)