2018-05-12 18:39:29 +02:00
|
|
|
---
|
|
|
|
layout: "functions"
|
2018-12-20 05:35:11 +01:00
|
|
|
page_title: "zipmap - Functions - Configuration Language"
|
2018-05-12 18:39:29 +02:00
|
|
|
sidebar_current: "docs-funcs-collection-zipmap"
|
|
|
|
description: |-
|
|
|
|
The zipmap function constructs a map from a list of keys and a corresponding
|
|
|
|
list of values.
|
|
|
|
---
|
|
|
|
|
|
|
|
# `zipmap` 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).
|
|
|
|
|
2018-05-12 18:39:29 +02:00
|
|
|
`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,
|
|
|
|
}
|
|
|
|
```
|