跳至主要内容

tostring 函数

tostring 将其参数转换为字符串值。

在 OpenTofu 中,显式类型转换很少需要,因为它会在需要时自动转换类型。仅当需要规范化模块输出中返回的类型时,才使用显式类型转换函数。

只有基本类型(字符串、数字和布尔值)以及 null 可以转换为字符串。tostring(null) 生成类型为 stringnull 值。所有其他值都会产生错误。

示例

代码块
> 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.