mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-21 10:47:34 -05:00
Signed-off-by: Janos <86970079+janosdebugs@users.noreply.github.com> Signed-off-by: Damian Stasik <920747+damianstasik@users.noreply.github.com> Signed-off-by: Roman Grinovski <roman.grinovski@gmail.com> Co-authored-by: Damian Stasik <920747+damianstasik@users.noreply.github.com> Co-authored-by: Roman Grinovski <roman.grinovski@gmail.com>
52 lines
1.2 KiB
Plaintext
52 lines
1.2 KiB
Plaintext
---
|
|
sidebar_label: merge
|
|
description: |-
|
|
The merge function takes an arbitrary number maps or objects, and returns a
|
|
single map or object that contains a merged set of elements from all
|
|
arguments.
|
|
---
|
|
|
|
# `merge` Function
|
|
|
|
`merge` takes an arbitrary number of maps or objects, and returns a single map
|
|
or object that contains a merged set of elements from all arguments.
|
|
|
|
If more than one given map or object defines the same key or attribute, then
|
|
the one that is later in the argument sequence takes precedence. If the
|
|
argument types do not match, the resulting type will be an object matching the
|
|
type structure of the attributes after the merging rules have been applied.
|
|
|
|
## Examples
|
|
|
|
```
|
|
> merge({a="b", c="d"}, {e="f", c="z"})
|
|
{
|
|
"a" = "b"
|
|
"c" = "z"
|
|
"e" = "f"
|
|
}
|
|
```
|
|
|
|
```
|
|
> merge({a="b"}, {a=[1,2], c="z"}, {d=3})
|
|
{
|
|
"a" = [
|
|
1,
|
|
2,
|
|
]
|
|
"c" = "z"
|
|
"d" = 3
|
|
}
|
|
```
|
|
|
|
The following example uses the expansion symbol (...) to transform the value into separate arguments. Refer to [Expanding Function Argument](../../language/expressions/function-calls.mdx#expanding-function-arguments) for details.
|
|
|
|
```
|
|
> merge([{a="b", c="d"}, {}, {e="f", c="z"}]...)
|
|
{
|
|
"a" = "b"
|
|
"c" = "z"
|
|
"e" = "f"
|
|
}
|
|
```
|