From 3583b31d19f2fa5c1f2bcbeda3daee39eb6fb519 Mon Sep 17 00:00:00 2001 From: "kierra.searle@ibm.com" Date: Thu, 14 Nov 2024 13:56:26 -0500 Subject: [PATCH 1/9] refactor: added additional prefix validation --- solutions/instance/variables.tf | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/solutions/instance/variables.tf b/solutions/instance/variables.tf index c1377431..0d4fba22 100644 --- a/solutions/instance/variables.tf +++ b/solutions/instance/variables.tf @@ -8,6 +8,10 @@ variable "prefix" { type = string description = "(Optional) Prefix to append 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])$", var.prefix)) && length(var.prefix) <= 16 + } } variable "existing_resource_group" { From 20f0c1803fc7cc081021bc4356572b5e41894574 Mon Sep 17 00:00:00 2001 From: "kierra.searle@ibm.com" Date: Thu, 14 Nov 2024 14:43:22 -0500 Subject: [PATCH 2/9] fix: added or null --- solutions/instance/variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/instance/variables.tf b/solutions/instance/variables.tf index 0d4fba22..1a0da161 100644 --- a/solutions/instance/variables.tf +++ b/solutions/instance/variables.tf @@ -10,7 +10,7 @@ variable "prefix" { 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])$", var.prefix)) && length(var.prefix) <= 16 + condition = var.prefix == null || can(regex("^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$", var.prefix)) && length(var.prefix) <= 16 } } From c6d061ed1bbaa7a014eede5d8402353c45cc8b7e Mon Sep 17 00:00:00 2001 From: "kierra.searle@ibm.com" Date: Thu, 14 Nov 2024 15:25:29 -0500 Subject: [PATCH 3/9] fix: added coalesce --- solutions/instance/variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/instance/variables.tf b/solutions/instance/variables.tf index 1a0da161..cc8a73cf 100644 --- a/solutions/instance/variables.tf +++ b/solutions/instance/variables.tf @@ -10,7 +10,7 @@ variable "prefix" { 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 = var.prefix == null || can(regex("^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$", var.prefix)) && length(var.prefix) <= 16 + condition = can(regex("^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$", var.prefix)) && length(coalesce(var.prefix, "")) <= 16 } } From fa4db1351ead590ccd1e4d663038e24d8680b6e5 Mon Sep 17 00:00:00 2001 From: "kierra.searle@ibm.com" Date: Thu, 14 Nov 2024 16:05:33 -0500 Subject: [PATCH 4/9] fix: updated coalesce --- solutions/instance/variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/instance/variables.tf b/solutions/instance/variables.tf index cc8a73cf..7e339089 100644 --- a/solutions/instance/variables.tf +++ b/solutions/instance/variables.tf @@ -10,7 +10,7 @@ variable "prefix" { 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])$", var.prefix)) && length(coalesce(var.prefix, "")) <= 16 + condition = can(regex("^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$", var.prefix)) && length(coalesce(var.prefix, " ")) <= 16 } } From e7f7460bc49729d5a20b9661bab7f17268b5849e Mon Sep 17 00:00:00 2001 From: "kierra.searle@ibm.com" Date: Thu, 14 Nov 2024 16:14:31 -0500 Subject: [PATCH 5/9] fix: updated coalesce --- solutions/instance/variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/instance/variables.tf b/solutions/instance/variables.tf index 7e339089..fe42924a 100644 --- a/solutions/instance/variables.tf +++ b/solutions/instance/variables.tf @@ -10,7 +10,7 @@ variable "prefix" { 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])$", var.prefix)) && length(coalesce(var.prefix, " ")) <= 16 + condition = can(regex("^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$", var.prefix)) && length(coalesce(var.prefix, "cos")) <= 16 } } From fd549579cc34d071bcd28aa2bced30b41713ef1d Mon Sep 17 00:00:00 2001 From: "kierra.searle@ibm.com" Date: Fri, 15 Nov 2024 10:19:03 -0500 Subject: [PATCH 6/9] fix: updated coalesce again --- solutions/instance/variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/instance/variables.tf b/solutions/instance/variables.tf index fe42924a..a348ffbb 100644 --- a/solutions/instance/variables.tf +++ b/solutions/instance/variables.tf @@ -10,7 +10,7 @@ variable "prefix" { 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])$", var.prefix)) && length(coalesce(var.prefix, "cos")) <= 16 + condition = can(regex("^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$", coalesce(var.prefix, "cos"))) && length(coalesce(var.prefix, "cos")) <= 16 } } From 3ac25adefb5016fae72a25fc67e0e9dbd6db5bdc Mon Sep 17 00:00:00 2001 From: "kierra.searle@ibm.com" Date: Mon, 6 Jan 2025 11:23:58 -0500 Subject: [PATCH 7/9] refactor: update condition --- solutions/instance/variables.tf | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/solutions/instance/variables.tf b/solutions/instance/variables.tf index a348ffbb..9d6c5adf 100644 --- a/solutions/instance/variables.tf +++ b/solutions/instance/variables.tf @@ -10,7 +10,10 @@ variable "prefix" { 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, "cos"))) && length(coalesce(var.prefix, "cos")) <= 16 + condition = anytrue([ + var.prefix == null, + can(regex("^([a-z]|[a-z][-a-z0-9]{0,14}[a-z0-9])$", var.prefix)) + ]) } } From 8267b05975c7b00e288bc3f5cbc799ef530c7233 Mon Sep 17 00:00:00 2001 From: "kierra.searle@ibm.com" Date: Mon, 6 Jan 2025 16:06:00 -0500 Subject: [PATCH 8/9] refactor: update condition --- solutions/instance/variables.tf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/solutions/instance/variables.tf b/solutions/instance/variables.tf index 854b87a8..cb8f09ba 100644 --- a/solutions/instance/variables.tf +++ b/solutions/instance/variables.tf @@ -10,9 +10,9 @@ variable "prefix" { 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 = anytrue([ - var.prefix == null, - can(regex("^([a-z]|[a-z][-a-z0-9]{0,14}[a-z0-9])$", var.prefix)) + condition = alltrue([ + can(regex("^([a-z]|[a-z][-a-z0-9]{0,14}[a-z0-9])$", var.prefix)), + length(regexall("^.*--.*", var.prefix)) == 0 ]) } } From 9ad9202953d33fce41ea83c5427ee333221d51d4 Mon Sep 17 00:00:00 2001 From: "kierra.searle@ibm.com" Date: Mon, 6 Jan 2025 16:57:17 -0500 Subject: [PATCH 9/9] fix: prefix validation update --- solutions/instance/variables.tf | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/solutions/instance/variables.tf b/solutions/instance/variables.tf index cb8f09ba..8a2f0a57 100644 --- a/solutions/instance/variables.tf +++ b/solutions/instance/variables.tf @@ -9,11 +9,14 @@ variable "prefix" { description = "(Optional) Prefix to append 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 = alltrue([ - can(regex("^([a-z]|[a-z][-a-z0-9]{0,14}[a-z0-9])$", var.prefix)), - length(regexall("^.*--.*", var.prefix)) == 0 + 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." } }