diff --git a/ibm_catalog.json b/ibm_catalog.json index e42fab3..6481306 100644 --- a/ibm_catalog.json +++ b/ibm_catalog.json @@ -64,7 +64,8 @@ }, { "key": "prefix", - "required": true + "required": true, + "description": "The prefix to add to all resources that this solution creates. To not use any prefix value, you can enter the string `__NULL__`." }, { "key": "use_existing_resource_group" @@ -217,7 +218,8 @@ }, { "key": "prefix", - "required": true + "required": true, + "description": "The prefix to add to all resources that this solution creates. To not use any prefix value, you can enter the string `__NULL__`." }, { "key": "use_existing_resource_group" diff --git a/solutions/enterprise/main.tf b/solutions/enterprise/main.tf index dafeb0c..a443e8a 100644 --- a/solutions/enterprise/main.tf +++ b/solutions/enterprise/main.tf @@ -4,7 +4,7 @@ module "resource_group" { source = "terraform-ibm-modules/resource-group/ibm" version = "1.1.6" - resource_group_name = var.use_existing_resource_group == false ? ((var.prefix != null && var.prefix != "") ? "${var.prefix}-${var.resource_group_name}" : var.resource_group_name) : null + resource_group_name = var.use_existing_resource_group == false ? try("${local.prefix}-${var.resource_group_name}", var.resource_group_name) : null existing_resource_group_name = var.use_existing_resource_group == true ? var.resource_group_name : null } @@ -13,10 +13,10 @@ module "resource_group" { ####################################################################################################################### locals { + prefix = var.prefix != null ? (var.prefix != "" ? var.prefix : null) : null create_new_kms_key = var.existing_kms_key_crn == null ? 1 : 0 # no need to create any KMS resources if passing an existing key - event_streams_key_name = var.prefix != null ? "${var.prefix}-${var.event_streams_key_name}" : var.event_streams_key_name - event_streams_key_ring_name = var.prefix != null ? "${var.prefix}-${var.event_streams_key_ring_name}" : var.event_streams_key_ring_name - + event_streams_key_name = try("${local.prefix}-${var.event_streams_key_name}", var.event_streams_key_name) + event_streams_key_ring_name = try("${local.prefix}-${var.event_streams_key_ring_name}", var.event_streams_key_ring_name) # tflint-ignore: terraform_unused_declarations validate_kms = var.existing_kms_instance_crn == null && var.existing_kms_key_crn == null ? tobool("Both 'existing_kms_instance_crn' and 'existing_kms_key_crn' input variables can not be null. Set 'existing_kms_instance_crn' to create a new KMS key or 'existing_kms_key_crn' to use an existing KMS key.") : true } @@ -145,7 +145,7 @@ resource "time_sleep" "wait_for_authorization_policy" { module "event_streams" { source = "../../modules/fscloud" resource_group_id = module.resource_group.resource_group_id - es_name = (var.prefix != null && var.prefix != "") ? "${var.prefix}-${var.event_streams_name}" : var.event_streams_name + es_name = try("${local.prefix}-${var.event_streams_name}", var.event_streams_name) kms_key_crn = local.kms_key_crn schemas = var.schemas region = var.region diff --git a/solutions/enterprise/variables.tf b/solutions/enterprise/variables.tf index 45f7885..110974f 100644 --- a/solutions/enterprise/variables.tf +++ b/solutions/enterprise/variables.tf @@ -12,7 +12,7 @@ variable "region" { variable "prefix" { type = string - description = "Optional. The prefix to append to all resources that this solution creates. Prefix is ignored if it is `null` or empty string (\"\")." + description = "The prefix to add to all resources that this solution creates. To not use any prefix value, you can set this value to `null` or an empty string." default = "enterprise" } diff --git a/solutions/quickstart/main.tf b/solutions/quickstart/main.tf index e2d6ff6..3558500 100644 --- a/solutions/quickstart/main.tf +++ b/solutions/quickstart/main.tf @@ -1,10 +1,14 @@ +locals { + prefix = var.prefix != null ? (var.prefix != "" ? var.prefix : null) : null +} + ####################################################################################################################### # Resource Group ####################################################################################################################### module "resource_group" { source = "terraform-ibm-modules/resource-group/ibm" version = "1.1.6" - resource_group_name = var.use_existing_resource_group == false ? ((var.prefix != null && var.prefix != "") ? "${var.prefix}-${var.resource_group_name}" : var.resource_group_name) : null + resource_group_name = var.use_existing_resource_group == false ? try("${local.prefix}-${var.resource_group_name}", var.resource_group_name) : null existing_resource_group_name = var.use_existing_resource_group == true ? var.resource_group_name : null } @@ -14,7 +18,7 @@ module "resource_group" { module "event_streams" { source = "../../" resource_group_id = module.resource_group.resource_group_id - es_name = (var.prefix != null && var.prefix != "") ? "${var.prefix}-${var.es_name}" : var.es_name + es_name = try("${local.prefix}-${var.es_name}", var.es_name) plan = var.plan region = var.region topics = var.topics diff --git a/solutions/quickstart/variables.tf b/solutions/quickstart/variables.tf index 178f62c..68f0bd9 100644 --- a/solutions/quickstart/variables.tf +++ b/solutions/quickstart/variables.tf @@ -6,7 +6,7 @@ variable "ibmcloud_api_key" { variable "prefix" { type = string - description = "Optional. The prefix to append to all resources that this solution creates. Prefix is ignored if it is `null` or empty string (\"\")." + description = "The prefix to add to all resources that this solution creates. To not use any prefix value, you can set this value to `null` or an empty string." default = "dev" }