Skip to content

no-nested-conditional

Prefer a named value or explicit input over chained Terraform conditional selections.

Why

Chained conditional branches obscure the value being selected and scatter deployment policy.

Fix

Extract a branch into a named local or pass a typed input from the caller. Preserve lazy evaluation, null guards and resource dependencies when extracting an expression.

Examples

Before — flagged A nested selection hides the selected configuration
main.tf
locals {
size = var.primary ? "large" : var.secondary ? "medium" : "small"
}
After — preferred The caller supplies the selected value
main.tf
variable "size" { type = string }
module "service" {
source = "./service"
size = var.size
}