Coder powers secure, scalable development across key industries — automotive, finance, government, and technology — enabling faster builds, tighter compliance, and seamless AI adoption in enterprise-grade cloud environments.
The validation block of a coder_parameter rejects values that your template can't use before Coder starts a build.
Coder supports several validation modes: minimum and maximum values, monotonic numbers, and regular expressions.
A validation rule can also depend on the values of other parameters.
Number validation
You can limit a number parameter to min and max boundaries.
You can also specify its monotonicity as increasing or decreasing to verify the current and new values.
Use the monotonic attribute for resources that can't be shrunk or grown without implications, like disk volume size.
data "coder_parameter" "instances" {
name = "Instances"
type = "number"
description = "Number of compute instances"
validation {
min = 1
max = 8
monotonic = "increasing"
}
}
It is possible to override the default error message for a number parameter, along with its associated min and/or max properties.
The following message placeholders are available {min}, {max}, and {value}.
data "coder_parameter" "instances" {
name = "Instances"
type = "number"
description = "Number of compute instances"
validation {
min = 1
max = 4
error = "Sorry, we can't provision too many instances - maximum limit: {max}, wanted: {value}."
}
}
A number parameter can also define options, and validations such as monotonic still apply to it.
String validation
You can validate a string parameter to match a regular expression.
The regex property requires a corresponding error property.
data "coder_parameter" "project_id" {
name = "Project ID"
description = "Alpha-numeric project ID"
validation {
regex = "^[a-z0-9]+$"
error = "Unfortunately, this isn't a valid project ID"
}
}
Validation that depends on other parameters
A parameter's validation block can use the values of other parameters.
This example sets both the default and the maximum CPU core count based on the selected repository.