Consistent types - length error. Best way to move forward?


I have an issue with a local variable i’m attempting to create for use by subsequent locals.

I’ve made the var names simple for the sake of this post, but the logic still applies:

local_variable = var.var1["enabled"] == true ? concat([var.var1], var.var2, var.var3, [var.var4], [var.var5]) : concat(var.var2, var.var3, [var.var4], [var.var5])

…which gives me the following error:

The true and false result expressions must have consistent types. The ‘true’ tuple has length 5, but the ‘false’ tuple has length 4.

I genuinely need this logic as i’m then using the variable to loop through and create flattened maps for various modules.

Is there a recommended approach here? I’ve tried a number of alternative functions and true/false contents, however i’m sure i’ve missed something simple!

Thanks in advance.

It hides relevant information though…

Specifically, we need to know if the elements being concatenated here are all the same types. If they are, use the tolist function to convert each tuple to a list… If not, you’re going to have to describe your use case in more detail.

Apologies, anything with square brackets around it (e.g. var1) is type object, anything without is a list(object).

I’ve tried with tolist() in various ways without any luck!