Skip to content

Commit 642ddac

Browse files
authored
feat: add UI Regex Validation (#712)
1 parent 14b0b7c commit 642ddac

File tree

2 files changed

+47
-7
lines changed

2 files changed

+47
-7
lines changed

ibm_catalog.json

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,14 @@
7070
},
7171
{
7272
"key": "prefix",
73-
"required": true
73+
"required": true,
74+
"value_constraints": [
75+
{
76+
"type": "regex",
77+
"description": "Prefix must begin with a lowercase letter and may contain only lowercase letters, digits, and hyphens '-'. It must not end with a hyphen('-'), and cannot contain consecutive hyphens ('--'). It should not exceed 16 characters.",
78+
"value": "^$|^__NULL__$|^[a-z](?!.*--)(?:[a-z0-9-]{0,14}[a-z0-9])?$"
79+
}
80+
]
7481
},
7582
{
7683
"key": "vpc_name",
@@ -87,7 +94,14 @@
8794
"key": "cloud_services"
8895
},
8996
{
90-
"key": "cloud_service_by_crn"
97+
"key": "cloud_service_by_crn",
98+
"value_constraints": [
99+
{
100+
"type": "regex",
101+
"description": "The value provided for 'cloud_service_by_crn' is not valid.",
102+
"value": "^__NULL__$|^\\[\\]$|^crn:v1:[^:]+:[^:]+:[^:]+:[^:]+:a/[0-9a-f]{32}(:[^:]*)*:{0,2}$"
103+
}
104+
]
91105
},
92106
{
93107
"key": "service_endpoints"

solutions/fully-configurable/variables.tf

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,28 @@ variable "region" {
1717

1818
variable "prefix" {
1919
type = string
20-
description = "Prefix to add to all resources created by this deployable architecture. To not use any prefix value, you can set this value to `null` or an empty string."
20+
nullable = true
21+
description = "The prefix to add to all resources that this solution creates (e.g `prod`, `test`, `dev`). To skip using a prefix, set this value to `null` or an empty string. [Learn more](https://terraform-ibm-modules.github.io/documentation/#/prefix.md)."
22+
2123
validation {
22-
condition = (var.prefix == null ? true :
24+
# - null and empty string is allowed
25+
# - Must not contain consecutive hyphens (--): length(regexall("--", var.prefix)) == 0
26+
# - Starts with a lowercase letter: [a-z]
27+
# - Contains only lowercase letters (a–z), digits (0–9), and hyphens (-)
28+
# - Must not end with a hyphen (-): [a-z0-9]
29+
condition = (var.prefix == null || var.prefix == "" ? true :
2330
alltrue([
24-
can(regex("^[a-z]{0,1}[-a-z0-9]{0,14}[a-z0-9]{0,1}$", var.prefix)),
25-
length(regexall("^.*--.*", var.prefix)) == 0
31+
can(regex("^[a-z][-a-z0-9]*[a-z0-9]$", var.prefix)),
32+
length(regexall("--", var.prefix)) == 0
2633
])
2734
)
28-
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."
35+
error_message = "Prefix must begin with a lowercase letter and may contain only lowercase letters, digits, and hyphens '-'. It must not end with a hyphen('-'), and cannot contain consecutive hyphens ('--')."
36+
}
37+
38+
validation {
39+
# must not exceed 16 characters in length
40+
condition = var.prefix == null || var.prefix == "" ? true : length(var.prefix) <= 16
41+
error_message = "Prefix must not exceed 16 characters."
2942
}
3043
}
3144

@@ -114,6 +127,19 @@ variable "cloud_service_by_crn" {
114127
})
115128
)
116129
default = []
130+
validation {
131+
condition = (
132+
length(var.cloud_service_by_crn) == 0 ? true : alltrue([
133+
for service in var.cloud_service_by_crn : can(
134+
regex(
135+
"^crn:v1:[^:]+:[^:]+:[^:]+:[^:]+:a/[0-9a-f]{32}(:[^:]*)*:{0,2}$",
136+
service.crn
137+
)
138+
)
139+
])
140+
)
141+
error_message = "The provided environment CRN in the input 'cloud_service_by_crn' in not valid."
142+
}
117143
}
118144

119145
variable "service_endpoints" {

0 commit comments

Comments
 (0)