Skip to main content
Variables can declare a type constraint. When set, Errand validates the value at run time and converts it to the declared type automatically.

Primitive types

TypeDescription
stringA UTF-8 string
numberAn integer or floating-point number
booltrue or false
variable "host" {
  type    = string
  default = "localhost"
}

variable "port" {
  type    = number
  default = 8080
}

variable "tls" {
  type    = bool
  default = false
}

Collection types

list

An ordered collection of values of the same type:
variable "services" {
  type    = list(string)
  default = ["api", "worker", "scheduler"]
}

task "build-all" {
  commands = [
    "for svc in ${join(' ', var.services)}; do go build ./cmd/$svc; done",
  ]
}

set

An unordered collection with unique values:
variable "environments" {
  type    = set(string)
  default = ["staging", "production"]
}

map

A collection of key-value pairs where all values share the same type:
variable "ports" {
  type    = map(number)
  default = {
    api     = 8080
    metrics = 9090
  }
}

task "run" {
  commands = ["./bin/app --port ${var.ports.api} --metrics-port ${var.ports.metrics}"]
}

object

A collection of named attributes with potentially different types:
variable "db" {
  type = object({
    host = string
    port = number
    name = string
  })
}

task "migrate" {
  commands = ["psql -h ${var.db.host} -p ${var.db.port} -d ${var.db.name} -f schema.sql"]
}

tuple

An ordered list where each position has a fixed type:
variable "range" {
  type    = tuple([number, number])
  default = [1, 100]
}

Optional attributes

Use optional(type) or optional(type, default) within an object to mark fields as optional:
variable "server" {
  type = object({
    host    = string
    port    = optional(number, 8080)
    tls     = optional(bool, false)
    comment = optional(string)
  })
  default = {
    host = "localhost"
  }
}
Fields declared with optional(type, default) use the given default when not provided. Fields declared with optional(type) default to null.

Omitting the type

Without a type, Errand accepts any value without validation:
variable "config" {
  default = "default-value"
}
When a value is passed from the command line with no declared type, it is always treated as a string.