opentofu/website/docs/configuration/functions/coalescelist.html.md
Kristin Laemmert 394cf7f25e
lang/funcs: add acc tests for functions (#21112)
* lang/funcs: testing of functions through the lang package API
The function-specific unit tests do not cover the HCL conversion that happens when the functions are called in a terraform configuration. For e.g., HCL converts sets to lists before passing it to the function. This means that we could not test passing a set in the function _unit_ tests.
This adds a higher-level acceptance test, plus a check that every (pure) function has a test.

* website/docs: update function documentation
2019-04-29 13:11:28 -04:00

1.0 KiB

layout page_title sidebar_current description
functions coalescelist - Functions - Configuration Language docs-funcs-collection-coalescelist The coalescelist function takes any number of list arguments and returns the first one that isn't empty.

coalescelist Function

-> Note: This page is about Terraform 0.12 and later. For Terraform 0.11 and earlier, see 0.11 Configuration Language: Interpolation Syntax.

coalescelist takes any number of list arguments and returns the first one that isn't empty.

Examples

> coalescelist(["a", "b"], ["c", "d"])
[
  "a",
  "b",
]
> coalescelist([], ["c", "d"])
[
  "c",
  "d",
]

To perform the coalescelist operation with a list of lists, use the ... symbol to expand the outer list as arguments:

> coalescelist([[], ["c", "d"]]...)
[
  "c",
  "d",
]
  • coalesce performs a similar operation with string arguments rather than list arguments.