The true and false result expressions must have consistent types: working around Terraform's type system

Many people struggle with how the ternary operator works with Terraform’s type system. Ternary operators won’t compile unless both true and false expressions have exactly the same type. See Inconsistent conditional result types fails for complex types · Issue #22405 · hashicorp/terraform · GitHub, amazon web services - The true and false result expressions must have consistent types. The given expressions are list of string and number, respectively - Stack Overflow, The true and false result expressions must have consistent types. The given expressions are object and tuple, respectively

However, in many cases it is ok that they don’t have the same exact type. Here is an example, trying to manipulate yaml data loaded from a file (m is an item from a yaml list, this is inside a [for m in … : …] construct:

This is not ok:
((length(var.regions) > 0) ? merge(m, { regions: var.regions }) : m)

This is ok: yamldecode(((length(var.regions) > 0) ? yamlencode(merge(m, { regions: var.regions })) : yamlencode(m)))

The workaround of encoding and decoding works, but is really ugly. Wouldn’t it be possible to somehow cast the expressions to the any type instead?