Skip to content

Commit a6a74eb

Browse files
committed
fix: use can() for null-safe variable validation in cluster_api_host
1 parent 165f5b5 commit a6a74eb

1 file changed

Lines changed: 8 additions & 14 deletions

File tree

variables.tf

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,10 @@ variable "cluster_api_host_private" {
3737
EOF
3838

3939
validation {
40-
condition = var.cluster_api_host_private == null || (
41-
var.cluster_api_host_private == trimspace(var.cluster_api_host_private) &&
42-
trimspace(var.cluster_api_host_private) != "" &&
43-
length(regexall("://", var.cluster_api_host_private)) == 0 &&
44-
length(regexall(":", var.cluster_api_host_private)) == 0 &&
45-
can(regex("^[0-9A-Za-z]([0-9A-Za-z-]*[0-9A-Za-z])?(\\.[0-9A-Za-z]([0-9A-Za-z-]*[0-9A-Za-z])?)*$", var.cluster_api_host_private))
46-
)
40+
condition = var.cluster_api_host_private == null || can(regex(
41+
"^[0-9A-Za-z]([0-9A-Za-z-]*[0-9A-Za-z])?(\\.[0-9A-Za-z]([0-9A-Za-z-]*[0-9A-Za-z])?)*$",
42+
var.cluster_api_host_private
43+
))
4744

4845
error_message = "cluster_api_host_private must be null or a non-empty DNS hostname without scheme or port (example: kube.example.com)."
4946
}
@@ -71,13 +68,10 @@ variable "cluster_api_host" {
7168
default = null
7269

7370
validation {
74-
condition = var.cluster_api_host == null || (
75-
var.cluster_api_host == trimspace(var.cluster_api_host) &&
76-
trimspace(var.cluster_api_host) != "" &&
77-
length(regexall("://", var.cluster_api_host)) == 0 &&
78-
length(regexall(":", var.cluster_api_host)) == 0 &&
79-
can(regex("^[0-9A-Za-z]([0-9A-Za-z-]*[0-9A-Za-z])?(\\.[0-9A-Za-z]([0-9A-Za-z-]*[0-9A-Za-z])?)*$", var.cluster_api_host))
80-
)
71+
condition = var.cluster_api_host == null || can(regex(
72+
"^[0-9A-Za-z]([0-9A-Za-z-]*[0-9A-Za-z])?(\\.[0-9A-Za-z]([0-9A-Za-z-]*[0-9A-Za-z])?)*$",
73+
var.cluster_api_host
74+
))
8175

8276
error_message = "cluster_api_host must be null or a non-empty hostname/IP without scheme or port (example: kube.example.com)."
8377
}

0 commit comments

Comments
 (0)