2018-05-12 18:39:29 +02:00
|
|
|
---
|
|
|
|
layout: "functions"
|
2018-12-20 05:35:11 +01:00
|
|
|
page_title: "coalesce - Functions - Configuration Language"
|
2018-05-12 18:39:29 +02:00
|
|
|
sidebar_current: "docs-funcs-collection-coalesce-x"
|
|
|
|
description: |-
|
2019-04-12 19:57:52 +02:00
|
|
|
The coalesce function takes any number of arguments and returns the
|
|
|
|
first one that isn't null nor empty.
|
2018-05-12 18:39:29 +02:00
|
|
|
---
|
|
|
|
|
|
|
|
# `coalesce` Function
|
|
|
|
|
2019-01-17 01:33:57 +01:00
|
|
|
-> **Note:** This page is about Terraform 0.12 and later. For Terraform 0.11 and
|
|
|
|
earlier, see
|
|
|
|
[0.11 Configuration Language: Interpolation Syntax](../../configuration-0-11/interpolation.html).
|
|
|
|
|
2019-04-12 19:57:52 +02:00
|
|
|
`coalesce` takes any number of arguments and returns the first one
|
|
|
|
that isn't null or an empty string.
|
2018-05-12 18:39:29 +02:00
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
```
|
|
|
|
> coalesce("a", "b")
|
|
|
|
a
|
|
|
|
> coalesce("", "b")
|
|
|
|
b
|
2019-04-12 19:57:52 +02:00
|
|
|
> coalesce(1,2)
|
|
|
|
1
|
2018-05-12 18:39:29 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
To perform the `coalesce` operation with a list of strings, use the `...`
|
|
|
|
symbol to expand the list as arguments:
|
|
|
|
|
|
|
|
```
|
|
|
|
> coalesce(["", "b"]...)
|
|
|
|
b
|
|
|
|
```
|
|
|
|
|
|
|
|
## Related Functions
|
|
|
|
|
|
|
|
* [`coalescelist`](./coalescelist.html) performs a similar operation with
|
2019-04-12 19:57:52 +02:00
|
|
|
list arguments rather than individual arguments.
|