Interview Prep/Terraform/Variables, Locals, Outputs and Types

Why does a conditional with different object types produce "Inconsistent conditional result types"?

AdvancedConceptVariables, Locals, Outputs and Types
Answer

Both branches of cond ? a : b must convert to a common type. Two objects with different attributes do not unify, so Terraform errors. Solve by returning the same shape in both branches (use null or empty values), wrapping the result in tomap/jsonencode, or by moving the choice to a for_each or count toggle on the resource.

All Terraform questions Roadmap: Terraform

More on Variables, Locals, Outputs and Types