Skip to content

Commit 9777b7b

Browse files
committed
Add some variable validations
1 parent e8fe8a7 commit 9777b7b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

variables.tf

+30
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ variable "tfc_address" {
77
type = string
88
description = "The HTTPS address of the TFC or TFE instance."
99
default = "https://app.terraform.io"
10+
validation {
11+
condition = startswith(var.tfc_address, "https://")
12+
error_message = "The address must start with 'https://'"
13+
}
1014
}
1115

1216
variable "tfc_org_name" {
@@ -18,18 +22,30 @@ variable "agent_cpu" {
1822
type = number
1923
description = "The CPU units allocated to the agent container(s). See https://docs.aws.amazon.com/AmazonECS/latest/developerguide/AWS_Fargate.html#fargate-tasks-size"
2024
default = 256
25+
validation {
26+
condition = var.agent_cpu >= 256
27+
error_message = "The CPU value must be at least 256."
28+
}
2129
}
2230

2331
variable "agent_memory" {
2432
type = number
2533
description = "The amount of memory, in MB, allocated to the agent container(s)."
2634
default = 512
35+
validation {
36+
condition = var.agent_memory >= 512
37+
error_message = "The memory value must be at least 512."
38+
}
2739
}
2840

2941
variable "agent_log_level" {
3042
type = string
3143
description = "The logging verbosity for the agent. Valid values are trace, debug, info (default), warn, and error."
3244
default = "info"
45+
validation {
46+
condition = contains(["trace", "debug", "info", "warn", "error"], var.agent_log_level)
47+
error_message = "Valid values: trace, debug, info, warn, error"
48+
}
3349
}
3450

3551
variable "agent_image" {
@@ -77,6 +93,10 @@ variable "cloudwatch_log_group_name" {
7793
variable "ecs_cluster_arn" {
7894
type = string
7995
description = "ARN of the ECS cluster where the agent will be deployed."
96+
validation {
97+
condition = can(regex("^arn:aws[a-z-]*:ecs:", var.ecs_cluster_arn))
98+
error_message = "Must be a valid ECS cluster ARN."
99+
}
80100
}
81101

82102
variable "use_spot_instances" {
@@ -88,11 +108,21 @@ variable "use_spot_instances" {
88108
variable "vpc_id" {
89109
type = string
90110
description = "ID of the VPC where the cluster is running."
111+
validation {
112+
condition = can(regex("^vpc-[a-zA-Z0-9]+$", var.vpc_id))
113+
error_message = "Must be a valid VPC ID."
114+
}
91115
}
92116

93117
variable "subnet_ids" {
94118
type = list(string)
95119
description = "IDs of the subnet(s) where agents can be deployed (public subnets required)"
120+
validation {
121+
condition = alltrue([
122+
for i in var.subnet_ids : can(regex("^subnet-[a-zA-Z0-9]+$", i))
123+
])
124+
error_message = "Must be a list of valid subnet IDs."
125+
}
96126
}
97127

98128
variable "task_policy_arns" {

0 commit comments

Comments
 (0)