Interview Prep/Terraform/Plan Errors and Unexpected Replacements

`Error: Inconsistent conditional result types` — `The true and false result expressions must have consistent types.`

IntermediateTroubleshootingPlan Errors and Unexpected Replacements
Answer

Likely causes → var.enabled ? { a = 1, b = "x" } : {} or two objects with different attributes; Terraform can't unify the types.

Diagnose → Read which attribute is absent in one branch.

Fix → Make both branches the same shape, or use merge()/tomap():

locals {
  extra = var.enabled ? { backup = "daily" } : tomap({})
}

Prevent → Use typed variables (map(string)) so values are converted consistently.

All Terraform questions

More on Plan Errors and Unexpected Replacements