mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-21 02:37:43 -05:00
Co-authored-by: Damian Stasik <920747+damianstasik@users.noreply.github.com> Co-authored-by: Roman Grinovski <roman.grinovski@gmail.com>
34 lines
674 B
Plaintext
34 lines
674 B
Plaintext
---
|
|
sidebar_label: tomap
|
|
description: The tomap function converts a value to a map.
|
|
---
|
|
|
|
# `tomap` Function
|
|
|
|
`tomap` converts its argument to a map value.
|
|
|
|
Explicit type conversions are rarely necessary in OpenTofu because it will
|
|
convert types automatically where required. Use the explicit type conversion
|
|
functions only to normalize types returned in module outputs.
|
|
|
|
## Examples
|
|
|
|
```
|
|
> tomap({"a" = 1, "b" = 2})
|
|
{
|
|
"a" = 1
|
|
"b" = 2
|
|
}
|
|
```
|
|
|
|
Since OpenTofu's concept of a map requires all of the elements to be of the
|
|
same type, mixed-typed elements will be converted to the most general type:
|
|
|
|
```
|
|
> tomap({"a" = "foo", "b" = true})
|
|
{
|
|
"a" = "foo"
|
|
"b" = "true"
|
|
}
|
|
```
|