2019-01-17 18:11:48 +01:00
|
|
|
---
|
2021-12-15 03:41:17 +01:00
|
|
|
page_title: tostring - Functions - Configuration Language
|
|
|
|
description: The tostring function converts a value to a string.
|
2019-01-17 18:11:48 +01:00
|
|
|
---
|
|
|
|
|
|
|
|
# `tostring` Function
|
|
|
|
|
|
|
|
`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.
|
|
|
|
|
2021-04-10 21:55:29 +02:00
|
|
|
Only the primitive types (string, number, and bool) and `null` can be converted to string.
|
2019-01-17 18:11:48 +01:00
|
|
|
All other values will produce an error.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
```
|
|
|
|
> tostring("hello")
|
|
|
|
hello
|
|
|
|
> tostring(1)
|
|
|
|
1
|
|
|
|
> tostring(true)
|
|
|
|
true
|
2021-04-10 21:55:29 +02:00
|
|
|
> tostring(null)
|
|
|
|
null
|
2019-01-17 18:11:48 +01:00
|
|
|
> tostring([])
|
|
|
|
Error: Invalid function argument
|
|
|
|
|
|
|
|
Invalid value for "v" parameter: cannot convert tuple to string.
|
|
|
|
```
|