concept
Operators and conditional expressions
Combine numeric and Boolean values with operators; use a Boolean conditional with compatible branch types. Equality compares type and value.
Formal Syntax & Structure
terraform syntaxterraform
Operators and conditional expressionsWorking Example
Example Snippetterraform
variable "requests" { type = number default = 80}
variable "enabled" { type = bool default = true}
locals { large = var.requests >= 100 tier = local.large ? "large" : "small" units = var.enabled ? (local.large ? 4 : 2) : 0}
output "capacity" { value = { tier = local.tier, units = local.units, active = var.enabled && local.units > 0 }}