Skip to content
Sarj Code Standards

conditional-resource-presence

Prefer stable Terraform resource presence or an explicit review justification.

Why

Conditional zero/empty instance selections duplicate provisioning paths and introduce indexed resource references. Temporary migration switches can outlive the migration and obscure the intended topology.

Fix

Prefer a direct migration and stable resource declarations. If optional provisioning is necessary, justify its lifetime and ownership in the PR or input description. Preserve state addresses and restore/cutover ordering when simplifying an existing deployment.

Examples

Before — flagged A migration switch retains two provisioning paths
main.tf
resource "example_service" "this" {
count = var.use_new ? 1 : 0
}
After — preferred The desired resource is declared directly
main.tf
resource "example_service" "this" {}