Skip to main content
Strings in Errand support template interpolation with ${}. Use it to embed variables, computed values, function calls, or any expression inside a string.

Syntax

"${expression}"
You can mix literal text and multiple interpolations in a single string:
"${var.registry}/${var.image}:${var.tag}"

In task commands

variable "version" {
  type = string
}

variable "app" {
  type    = string
  default = "api"
}

task "build" {
  commands = [
    "go build -ldflags \"-X main.version=${var.version}\" -o bin/${var.app} ./cmd/${var.app}",
  ]
}

In computed expressions

computed "image" {
  expression = "${env("CI_REGISTRY", "registry.example.com")}/${var.app}:${var.version}"
}

Function calls in interpolation

Any function call can appear inside ${}:
variable "branch" {
  type = string
}

task "build" {
  commands = ["docker build -t myapp:${replace(lower(var.branch), "/", "-")} ."]
}

Escaping

To include a literal ${ in a string, escape the dollar sign with an extra $:
commands = ["echo $${HOME}"]
This outputs ${HOME} to the shell, which the shell then expands. Without escaping, Errand would try to evaluate HOME as an expression.

Conditional expressions

Ternary-style conditionals work inside interpolations:
variable "debug" {
  type    = bool
  default = false
}

task "run" {
  commands = ["./bin/app ${var.debug ? "--debug" : ""}"]
}