mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-21 10:47:34 -05:00
Co-authored-by: Damian Stasik <920747+damianstasik@users.noreply.github.com> Co-authored-by: Roman Grinovski <roman.grinovski@gmail.com>
37 lines
878 B
Plaintext
37 lines
878 B
Plaintext
---
|
|
sidebar_label: tobool
|
|
description: The tobool function converts a value to boolean.
|
|
---
|
|
|
|
# `tobool` Function
|
|
|
|
`tobool` converts its argument to a boolean 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.
|
|
|
|
Only boolean values, `null`, and the exact strings `"true"` and `"false"` can be
|
|
converted to boolean. All other values will produce an error.
|
|
|
|
## Examples
|
|
|
|
```
|
|
> tobool(true)
|
|
true
|
|
> tobool("true")
|
|
true
|
|
> tobool(null)
|
|
null
|
|
> tobool("no")
|
|
Error: Invalid function argument
|
|
|
|
Invalid value for "v" parameter: cannot convert "no" to bool: only the strings
|
|
"true" or "false" are allowed.
|
|
|
|
> tobool(1)
|
|
Error: Invalid function argument
|
|
|
|
Invalid value for "v" parameter: cannot convert number to bool.
|
|
```
|