github.com/hugorut/terraform@v1.1.3/website/docs/language/functions/coalesce.mdx (about)

     1  ---
     2  page_title: coalesce - Functions - Configuration Language
     3  description: |-
     4    The coalesce function takes any number of arguments and returns the
     5    first one that isn't null nor empty.
     6  ---
     7  
     8  # `coalesce` Function
     9  
    10  `coalesce` takes any number of arguments and returns the first one
    11  that isn't null or an empty string.
    12  
    13  All of the arguments must be of the same type. Terraform will try to
    14  convert mismatched arguments to the most general of the types that all
    15  arguments can convert to, or return an error if the types are incompatible.
    16  The result type is the same as the type of all of the arguments.
    17  
    18  ## Examples
    19  
    20  ```
    21  > coalesce("a", "b")
    22  a
    23  > coalesce("", "b")
    24  b
    25  > coalesce(1,2)
    26  1
    27  ```
    28  
    29  To perform the `coalesce` operation with a list of strings, use the `...`
    30  symbol to expand the list as arguments:
    31  
    32  ```
    33  > coalesce(["", "b"]...)
    34  b
    35  ```
    36  
    37  Terraform attempts to select a result type that all of the arguments can
    38  convert to, so mixing argument types may produce surprising results due to
    39  Terraform's automatic type conversion rules:
    40  
    41  ```
    42  > coalesce(1, "hello")
    43  "1"
    44  > coalesce(true, "hello")
    45  "true"
    46  > coalesce({}, "hello")
    47  
    48  Error: Error in function call
    49  
    50  Call to function "coalesce" failed: all arguments must have the same type.
    51  ```
    52  
    53  ## Related Functions
    54  
    55  * [`coalescelist`](/language/functions/coalescelist) performs a similar operation with
    56    list arguments rather than individual arguments.