Skip to content

Conditionals & loops

scale {
replicas = var.environment == "production" ? 3 : 1
}
if {
condition = var.environment == "production"
deployment "extra-consumer" {
container "consumer" {
image = image("api")
}
}
}

Generate multiple resources from a list variable:

values.json
{
"tenants": [
{"name": "acme", "domain": "acme.example.com", "plan": "enterprise"},
{"name": "demo", "domain": "demo.example.com", "plan": "starter"}
]
}
for "tenant" "var.tenants" {
deployment "booking" {
name = "booking-${tenant.name}"
container "booking" {
image = image("booking")
env {
TENANT_ID = tenant.name
}
}
scale {
replicas = tenant.plan == "enterprise" ? 3 : 1
}
service {}
ingress {
host = tenant.domain
tls = true
}
}
}
Terminal window
kdef render --dir k8s/ --values values.json