mirror of
https://github.com/opentffoundation/opentf.git
synced 2026-05-26 13:03:36 -04:00
It's not normally necessary to make explicit type conversions in Terraform because the language implicitly converts as necessary, but explicit conversions are useful in a few specialized cases: - When defining output values for a reusable module, it may be desirable to force a "cleaner" output type than would naturally arise from a computation, such as forcing a string containing digits into a number. - Our 0.12upgrade mechanism will use some of these to replace use of the undocumented, hidden type conversion functions in HIL, and force particular type interpretations in some tricky cases. - We've found that type conversion functions can be useful as _temporary_ workarounds for bugs in Terraform and in providers where implicit type conversion isn't working correctly or a type constraint isn't specified precisely enough for the automatic conversion behavior. These all follow the same convention of being named "to" followed by a short type name. Since we've had a long-standing convention of running all the words together in lowercase in function names, we stick to that here even though some of these names are quite strange, because these should be rarely-used functions anyway.
43 lines
975 B
Markdown
43 lines
975 B
Markdown
---
|
|
layout: "functions"
|
|
page_title: "map - Functions - Configuration Language"
|
|
sidebar_current: "docs-funcs-collection-map"
|
|
description: |-
|
|
The map function constructs a map from some given elements.
|
|
---
|
|
|
|
# `map` Function
|
|
|
|
~> **This function is deprecated.** From Terraform v0.12, the Terraform
|
|
language has built-in syntax for creating maps using the `{` and `}`
|
|
delimiters. Use the built-in syntax instead. The `map` function will be
|
|
removed in a future version of Terraform.
|
|
|
|
`map` takes an even number of arguments and returns a map whose elements
|
|
are constructed from consecutive pairs of arguments.
|
|
|
|
## Examples
|
|
|
|
```
|
|
> map("a", "b", "c", "d")
|
|
{
|
|
"a" = "b"
|
|
"c" = "d"
|
|
]
|
|
```
|
|
|
|
Do not use the above form in Terraform v0.12 or above. Instead, use the
|
|
built-in map construction syntax, which achieves the same result:
|
|
|
|
```
|
|
> {"a" = "b", "c" = "d"}
|
|
{
|
|
"a" = "b"
|
|
"c" = "d"
|
|
]
|
|
```
|
|
|
|
## Related Functions
|
|
|
|
* [`tomap`](./tomap.html) performs a type conversion to a map type.
|