Dynamic argument with if conditional

Hi @merceskoba,

The [*] operator is called the “splat” operator, and you can find documentation about it in the section Splat Expressions. In particular, the special behavior of turning a null value into an empty list is covered at the end of that section:

Splat expressions are for lists only (and thus cannot be used to reference resources created with for_each, which are represented as maps in Terraform). However, if a splat expression is applied to a value that is not a list or tuple then the value is automatically wrapped in a single-element list before processing.

For example, var.single_object[*].id is equivalent to [var.single_object][*].id, or effectively [var.single_object.id]. This behavior is not interesting in most cases, but it is particularly useful when referring to resources that may or may not have count set, and thus may or may not produce a tuple value:

aws_instance.example[*].id

The above will produce a list of ids whether aws_instance.example has count set or not, avoiding the need to revise various other expressions in the configuration when a particular resource switches to and from having count set.

The documentation talks about count resources as its main example. It doesn’t talk about a variable that might be null or not, but it’s a different application of the same behavior.