How best to make result expressions have consistent types?

I have a boolean use_bastion and I’m trying to set value based on condition but it fails due to inconsistent types.

value = var.use_bastion ? module.inf[0].worker : “”

Error: Inconsistent conditional result types

module.inf[0].worker is tuple with 3 elements
var.use_bastion is true

The true and false result expressions must have consistent types. The given expressions are tuple and string, respectively.

How can I make these types the same type for comparison? Or is there a better way to perform this comparison?

The issue here is that your fallback value for module.inf[0].worker is an empty string, rather than a tuple (which is Terraform’s default type for sequences). If use_bastion is false, what do you want the value to be?

Options that might be useful to consider include:

  • [], an empty tuple
  • tolist([]), an empty list
  • null, the non-existence of a value
  • ["a", 1, true] or whatever else makes sense as a “default” value semantically

Hope this helps!

1 Like

Ah great, it sure does; I used [ ] in my case. Cheers!