github.com/muratcelep/terraform@v1.1.0-beta2-not-internal-4/website/docs/language/functions/coalesce.html.md (about)

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