Files
opentf/website/docs/configuration/functions/tomap.html.md
Martin Atkins 2f8f7d6f4d lang/funcs: Type conversion functions
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.
2019-01-17 10:01:47 -08:00

784 B

layout, page_title, sidebar_current, description
layout page_title sidebar_current description
functions tomap - Functions - Configuration Language docs-funcs-conversion-tomap 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 Terraform 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 Terraform'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"
}