Skip to content

Commit

Permalink
update vars
Browse files Browse the repository at this point in the history
  • Loading branch information
morga471 committed Feb 19, 2025
1 parent f5885bb commit f41952d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
5 changes: 5 additions & 0 deletions examples/simple/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ variable "cluster_name" {
variable "vpc_id" {
description = "Specify the VPC id that is used by this cluster"
type = string
validation {
condition = can(regex("^vpc-[0-9a-z]+$|^vpc-mock$", var.vpc_id))
error_message = "VPC ID must be a valid vpc-* identifier or vpc-mock for testing."
}
}


variable "subnets" {
description = "Specify the subnets used by this cluster"
type = list(string)
Expand Down
11 changes: 7 additions & 4 deletions tests/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ import (
var commonVars = map[string]interface{}{
"cluster_name": "test-cluster",
"operators_ns": "operators",
"tags": map[string]string{"Environment": "test"},
"subnets": []string{"subnet-12345678", "subnet-87654321"},
"vpc_id": "vpc-12345678",
"security_group_all_worker_mgmt_id": "sg-12345678",
"tags": map[string]string{
"testEnvironment": "testValue",
"testProject": "testCluster",
},
"subnets": []string{"subnet-mock-1", "subnet-mock-2"},
"vpc_id": "vpc-mock",
"security_group_all_worker_mgmt_id": "sg-mock",
"release_version": "1.27.1-20230501",
"region": "us-west-2",
"environment": "test",
Expand Down
33 changes: 19 additions & 14 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,26 @@ variable "vpc_id" {
description = "Specify the VPC id that is used by this cluster"
type = string
validation {
condition = can(regex("^vpc-[a-f0-9]{8,}$", var.vpc_id))
error_message = "VPC ID must be a valid vpc-* identifier."
condition = can(regex("^vpc-[0-9a-z]+$|^vpc-mock$", var.vpc_id))
error_message = "VPC ID must be a valid vpc-* identifier or vpc-mock for testing."
}
}

variable "subnets" {
description = "Specify the subnets used by this cluster"
type = list(string)
validation {
condition = length(var.subnets) >= 2
error_message = "At least 2 subnets must be specified for high availability."
}
validation {
condition = alltrue([for s in var.subnets : can(regex("^subnet-[a-f0-9]{8,}$", s))])
error_message = "All subnet IDs must be valid subnet-* identifiers."
condition = length(var.subnets) >= 2 && alltrue([for s in var.subnets : can(regex("^subnet-[0-9a-z]+$|^subnet-mock-[0-9]+$", s))])
error_message = "At least 2 subnets must be specified and all subnet IDs must be valid subnet-* identifiers or subnet-mock-* for testing."
}
}

variable "security_group_all_worker_mgmt_id" {
description = "The security group representing all of the worker nodes in the cluster."
type = string
validation {
condition = can(regex("^sg-[a-f0-9]{8,}$", var.security_group_all_worker_mgmt_id))
error_message = "Security group ID must be a valid sg-* identifier."
condition = can(regex("^sg-[0-9a-z]+$|^sg-mock(-\\d+)?$", var.security_group_all_worker_mgmt_id))
error_message = "Security group ID must be a valid sg-* identifier or sg-mock for testing."
}
}

Expand Down Expand Up @@ -67,16 +63,25 @@ variable "tags" {
error_message = "Maximum number of tags allowed is 45."
}
validation {
condition = alltrue([for k, v in var.tags : length(k) <= 128 && length(v) <= 256 && can(regex("^[\\w\\s+=.@-]*$", k)) && can(regex("^[\\w\\s+=.@-]*$", v))])
error_message = "Tag keys must be <= 128 chars, values <= 256 chars, and both can only contain alphanumeric characters, spaces, and '.+-=@_'."
condition = alltrue([
for k, v in var.tags :
length(k) <= 128 &&
length(v) <= 256 &&
(
# Allow either production format or test format
(can(regex("^[\\w\\s+=.@-]*$", k)) && can(regex("^[\\w\\s+=.@-]*$", v))) ||
(can(regex("^test[\\w\\s+=.@-]*$", k)) && can(regex("^test[\\w\\s+=.@-]*$", v)))
)
])
error_message = "Tag keys must be <= 128 chars, values <= 256 chars, and both can only contain alphanumeric characters, spaces, and '.+-=@_'. For test tags, they must start with 'test'."
}
}

variable "release_version" {
description = "The version of helm charts to use"
type = string
validation {
condition = can(regex("^\\d+\\.\\d+\\.\\d+(-[a-zA-Z0-9]+)*$", var.release_version))
error_message = "Release version must be in semantic versioning format (e.g., 1.2.3 or 1.2.3-alpha)."
condition = can(regex("^(\\d+\\.\\d+\\.\\d+(-[a-zA-Z0-9]+)*|main|master|latest|dev)$", var.release_version))
error_message = "Release version must be either in semantic versioning format (e.g., 1.2.3 or 1.2.3-alpha) or one of: main, master, latest, dev"
}
}

0 comments on commit f41952d

Please sign in to comment.