Terraform
tostring Function
⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️
[!IMPORTANT]
Documentation Update: Product documentation previously located in/website
has moved to thehashicorp/web-unified-docs
repository, where all product documentation is now centralized. Please make contributions directly toweb-unified-docs
, since changes to/website
in this repository will not appear on developer.hashicorp.com. ⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️
tostring
converts its argument to a string 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.
Only the primitive types (string, number, and bool) and null
can be converted to string.
tostring(null)
produces a null
value of type string
. All other values produce an error.
Examples
> tostring("hello")
"hello"
> tostring(1)
"1"
> tostring(true)
"true"
> tostring(null)
tostring(null)
> tostring([])
Error: Invalid function argument
Invalid value for "v" parameter: cannot convert tuple to string.