From 19484b0099c38d66a8a68936c6d6c61431790461 Mon Sep 17 00:00:00 2001 From: "kierra.searle@ibm.com" Date: Fri, 15 Nov 2024 11:25:35 -0500 Subject: [PATCH 1/5] fix: added prefix validation --- solutions/standard/variables.tf | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/solutions/standard/variables.tf b/solutions/standard/variables.tf index 7d3f96af..d1b7f31e 100644 --- a/solutions/standard/variables.tf +++ b/solutions/standard/variables.tf @@ -36,6 +36,10 @@ variable "prefix" { type = string description = "(Optional) Prefix to add to all resources created by this solution." default = null + validation { + error_message = "Prefix must begin with a lowercase letter and contain only lowercase letters, numbers, and - characters. Prefixes must end with a lowercase letter or number and be 16 or fewer characters." + condition = can(regex("^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$", coalesce(var.prefix, "en"))) && length(coalesce(var.prefix, "en")) <= 16 + } } ######################################################################################################################## From 4078be5148010484a85a84831fc8e82e5071eba8 Mon Sep 17 00:00:00 2001 From: "kierra.searle@ibm.com" Date: Mon, 6 Jan 2025 16:15:57 -0500 Subject: [PATCH 2/5] fix: prefix validation update --- solutions/standard/variables.tf | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/solutions/standard/variables.tf b/solutions/standard/variables.tf index cedc93a6..fc1a2cc5 100644 --- a/solutions/standard/variables.tf +++ b/solutions/standard/variables.tf @@ -46,8 +46,14 @@ variable "prefix" { description = "(Optional) Prefix to add to all resources created by this solution." default = null validation { - error_message = "Prefix must begin with a lowercase letter and contain only lowercase letters, numbers, and - characters. Prefixes must end with a lowercase letter or number and be 16 or fewer characters." - condition = can(regex("^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$", coalesce(var.prefix, "en"))) && length(coalesce(var.prefix, "en")) <= 16 + condition = anytrue([ + var.prefix == null, + alltrue([ + can(regex("^([a-z]|[a-z][-a-z0-9]{0,14}[a-z0-9])$", var.prefix)), + length(regexall("^.*--.*", var.prefix)) == 0 + ]) + ]) + error_message = "Prefix must begin with a lowercase letter, contain only lowercase letters, numbers, and - characters. Prefixes must end with a lowercase letter or number and be 16 or fewer characters." } } From e3fcd2dabc064f642cff3a0ef82f57cea07ec487 Mon Sep 17 00:00:00 2001 From: "kierra.searle@ibm.com" Date: Tue, 21 Jan 2025 16:40:07 -0500 Subject: [PATCH 3/5] fix: prefix validation --- solutions/standard/variables.tf | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/solutions/standard/variables.tf b/solutions/standard/variables.tf index fc1a2cc5..7b3fc313 100644 --- a/solutions/standard/variables.tf +++ b/solutions/standard/variables.tf @@ -43,16 +43,15 @@ variable "existing_monitoring_crn" { variable "prefix" { type = string - description = "(Optional) Prefix to add to all resources created by this solution." + 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." default = null validation { - condition = anytrue([ - var.prefix == null, + condition = (var.prefix == null ? true : alltrue([ - can(regex("^([a-z]|[a-z][-a-z0-9]{0,14}[a-z0-9])$", var.prefix)), + can(regex("^([a-z]|[a-z][-a-z0-9]{0,14}[a-z0-9])$|^$", var.prefix)), length(regexall("^.*--.*", var.prefix)) == 0 ]) - ]) + ) error_message = "Prefix must begin with a lowercase letter, contain only lowercase letters, numbers, and - characters. Prefixes must end with a lowercase letter or number and be 16 or fewer characters." } } From 72ee4123c26af54df02fd6c4c729e98add8ede5c Mon Sep 17 00:00:00 2001 From: "kierra.searle@ibm.com" Date: Mon, 10 Feb 2025 11:36:32 -0500 Subject: [PATCH 4/5] fix: better regex --- solutions/standard/variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/standard/variables.tf b/solutions/standard/variables.tf index 7b3fc313..822fe137 100644 --- a/solutions/standard/variables.tf +++ b/solutions/standard/variables.tf @@ -48,7 +48,7 @@ variable "prefix" { validation { condition = (var.prefix == null ? true : alltrue([ - can(regex("^([a-z]|[a-z][-a-z0-9]{0,14}[a-z0-9])$|^$", var.prefix)), + can(regex("^[a-z]{0,1}[-a-z0-9]{0,11}[a-z0-9]{0,1}$", var.prefix)), length(regexall("^.*--.*", var.prefix)) == 0 ]) ) From d024fe123fac39608e98f27dc255666c45b867b5 Mon Sep 17 00:00:00 2001 From: "kierra.searle@ibm.com" Date: Tue, 11 Feb 2025 15:07:17 -0500 Subject: [PATCH 5/5] fix: wrong prefix length --- solutions/standard/variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/standard/variables.tf b/solutions/standard/variables.tf index 9f3f9f17..69abef7c 100644 --- a/solutions/standard/variables.tf +++ b/solutions/standard/variables.tf @@ -48,7 +48,7 @@ variable "prefix" { validation { condition = (var.prefix == null ? true : alltrue([ - can(regex("^[a-z]{0,1}[-a-z0-9]{0,11}[a-z0-9]{0,1}$", var.prefix)), + can(regex("^[a-z]{0,1}[-a-z0-9]{0,14}[a-z0-9]{0,1}$", var.prefix)), length(regexall("^.*--.*", var.prefix)) == 0 ]) )