From f41952d6fd431e56a363231d6de4011f6190a0ab Mon Sep 17 00:00:00 2001 From: "Matthew C. Morgan" Date: Wed, 19 Feb 2025 12:26:29 -0500 Subject: [PATCH] update vars --- examples/simple/variables.tf | 5 +++++ tests/test_helpers.go | 11 +++++++---- variables.tf | 33 +++++++++++++++++++-------------- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/examples/simple/variables.tf b/examples/simple/variables.tf index c3ba8ca..1f09513 100644 --- a/examples/simple/variables.tf +++ b/examples/simple/variables.tf @@ -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) diff --git a/tests/test_helpers.go b/tests/test_helpers.go index 4dc3e7e..cdb9dc5 100644 --- a/tests/test_helpers.go +++ b/tests/test_helpers.go @@ -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", diff --git a/variables.tf b/variables.tf index 8592348..1894cfb 100644 --- a/variables.tf +++ b/variables.tf @@ -11,8 +11,8 @@ 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." } } @@ -20,12 +20,8 @@ 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." } } @@ -33,8 +29,8 @@ 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." } } @@ -67,8 +63,17 @@ 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'." } } @@ -76,7 +81,7 @@ 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" } }