Skip to content

Commit 293ec2e

Browse files
arya-girish-kArya Girish K
andauthored
fix: updated the default value of the prefix input to be "dev" in the DA (#372)
* refactor: Update prefix logic in DA * fix: Update default value for prefix * fix: Added description * SKIP UPGRADE TEST * fix: update prefix value * fix: Updated prefix logic with try() * fix: Resolved the comments --------- Co-authored-by: Arya Girish K <arya.girish.k@ibm.com>
1 parent 5c6d0cb commit 293ec2e

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

ibm_catalog.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@
6060
"key": "ibmcloud_api_key"
6161
},
6262
{
63-
"key": "prefix"
63+
"key": "prefix",
64+
"required": true,
65+
"decsription": "Prefix to add to all resources created by this solution. To not use any prefix value, you can enter the string `__NULL__`."
6466
},
6567
{
6668
"key": "use_existing_resource_group"

solutions/standard/main.tf

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module "resource_group" {
77
count = var.existing_en_instance_crn == null ? 1 : 0
88
source = "terraform-ibm-modules/resource-group/ibm"
99
version = "1.1.6"
10-
resource_group_name = var.use_existing_resource_group == false ? (var.prefix != null ? "${var.prefix}-${var.resource_group_name}" : var.resource_group_name) : null
10+
resource_group_name = var.use_existing_resource_group == false ? try("${local.prefix}-${var.resource_group_name}", var.resource_group_name) : null
1111
existing_resource_group_name = var.use_existing_resource_group == true ? var.resource_group_name : null
1212
}
1313

@@ -20,6 +20,7 @@ locals {
2020
# Validate that a value has been passed for 'existing_kms_instance_crn' and 'kms_endpoint_url' if not using existing EN instance
2121
# tflint-ignore: terraform_unused_declarations
2222
validate_kms_input = (var.existing_kms_instance_crn == null || var.kms_endpoint_url == null) && var.existing_en_instance_crn == null ? tobool("A value for 'existing_kms_instance_crn' and 'kms_endpoint_url' must be passed when no value is passed for 'existing_en_instance_crn'.") : true
23+
prefix = var.prefix != null ? (var.prefix != "" ? var.prefix : null) : null
2324
}
2425

2526
# If existing KMS root key CRN passed, parse details from it
@@ -67,13 +68,13 @@ locals {
6768
# Create cross account COS / KMS auth policy if not using existing EN instance, if not using existing bucket, if 'skip_cos_kms_auth_policy' is false, and if a value is passed for 'ibmcloud_kms_api_key'
6869
create_cross_account_cos_kms_auth_policy = var.existing_en_instance_crn == null && var.existing_cos_bucket_name == null && !var.skip_cos_kms_auth_policy && var.ibmcloud_kms_api_key != null
6970
# If a prefix value is passed, add it to the EN key name
70-
en_key_name = var.prefix != null ? "${var.prefix}-${var.en_key_name}" : var.en_key_name
71+
en_key_name = try("${local.prefix}-${var.en_key_name}", var.en_key_name)
7172
# If a prefix value is passed, add it to the EN key ring name
72-
en_key_ring_name = var.prefix != null ? "${var.prefix}-${var.en_key_ring_name}" : var.en_key_ring_name
73+
en_key_ring_name = try("${local.prefix}-${var.en_key_ring_name}", var.en_key_ring_name)
7374
# If a prefix value is passed, add it to the COS key name
74-
cos_key_name = var.prefix != null ? "${var.prefix}-${var.cos_key_name}" : var.cos_key_name
75+
cos_key_name = try("${local.prefix}-${var.cos_key_name}", var.cos_key_name)
7576
# If a prefix value is passed, add it to the COS key ring name
76-
cos_key_ring_name = var.prefix != null ? "${var.prefix}-${var.cos_key_ring_name}" : var.cos_key_ring_name
77+
cos_key_ring_name = try("${local.prefix}-${var.cos_key_ring_name}", var.cos_key_ring_name)
7778
# Determine the COS KMS key CRN (new key or existing key). It will only have a value if not using an existing bucket or existing EN instance
7879
cos_kms_key_crn = var.existing_en_instance_crn != null || 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", local.cos_key_ring_name, local.cos_key_name)].crn
7980
# If existing KMS instance CRN passed, parse the key ID from it
@@ -232,10 +233,10 @@ locals {
232233
# If a bucket name is passed, or an existing EN CRN is passed; do not create COS resources
233234
create_cos_bucket = var.existing_cos_bucket_name != null || var.existing_en_instance_crn != null ? false : true
234235
# determine COS details
235-
cos_bucket_name = var.existing_cos_bucket_name != null ? var.existing_cos_bucket_name : local.create_cos_bucket ? (var.prefix != null ? "${var.prefix}-${var.cos_bucket_name}" : var.cos_bucket_name) : null
236+
cos_bucket_name = var.existing_cos_bucket_name != null ? var.existing_cos_bucket_name : local.create_cos_bucket ? try("${local.prefix}-${var.cos_bucket_name}", var.cos_bucket_name) : null
236237
cos_bucket_name_with_suffix = var.existing_cos_bucket_name != null ? var.existing_cos_bucket_name : local.create_cos_bucket ? module.cos[0].bucket_name : null
237238
cos_bucket_region = var.cos_bucket_region != null ? var.cos_bucket_region : var.cross_region_location != null ? null : var.region
238-
cos_instance_name = var.prefix != null ? "${var.prefix}-${var.cos_instance_name}" : var.cos_instance_name
239+
cos_instance_name = try("${local.prefix}-${var.cos_instance_name}", var.cos_instance_name)
239240
cos_endpoint = var.existing_cos_bucket_name == null ? (local.create_cos_bucket ? "https://${module.cos[0].s3_endpoint_direct}" : null) : var.existing_cos_endpoint
240241
# If not using existing EN instance, and if existing COS instance CRN passed, parse the GUID from it, otherwise get GUID from COS module output
241242
cos_instance_guid = var.existing_en_instance_crn == null ? var.existing_cos_instance_crn == null ? module.cos[0].cos_instance_guid : module.cos_instance_crn_parser[0].service_instance : null
@@ -304,7 +305,7 @@ module "event_notifications" {
304305
source = "../.."
305306
resource_group_id = module.resource_group[0].resource_group_id
306307
region = var.region
307-
name = var.prefix != null ? "${var.prefix}-${var.event_notification_name}" : var.event_notification_name
308+
name = try("${local.prefix}-${var.event_notification_name}", var.event_notification_name)
308309
plan = var.service_plan
309310
tags = var.tags
310311
service_endpoints = var.service_endpoints

solutions/standard/variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ variable "existing_monitoring_crn" {
4343

4444
variable "prefix" {
4545
type = string
46-
description = "(Optional) Prefix to add to all resources created by this solution."
47-
default = null
46+
description = "(Optional) Prefix to add to all resources created by this solution. To not use any prefix value, you can set this value to `null` or an empty string."
47+
default = "dev"
4848
}
4949

5050
########################################################################################################################

0 commit comments

Comments
 (0)