terraform/website/docs/language/functions/zipmap.mdx

34 lines
798 B
Plaintext
Raw Normal View History

---
2021-12-15 03:41:17 +01:00
page_title: zipmap - Functions - Configuration Language
description: |-
The zipmap function constructs a map from a list of keys and a corresponding
list of values.
---
# `zipmap` Function
`zipmap` constructs a map from a list of keys and a corresponding list of
values.
```hcl
zipmap(keyslist, valueslist)
```
Both `keyslist` and `valueslist` must be of the same length. `keyslist` must
be a list of strings, while `valueslist` can be a list of any type.
Each pair of elements with the same index from the two lists will be used
as the key and value of an element in the resulting map. If the same value
appears multiple times in `keyslist` then the value with the highest index
is used in the resulting map.
## Examples
```
> zipmap(["a", "b"], [1, 2])
{
"a" = 1
"b" = 2
}
```