github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/website/docs/configuration/functions/tobool.html.md (about)

     1  ---
     2  layout: "functions"
     3  page_title: "tobool - Functions - Configuration Language"
     4  sidebar_current: "docs-funcs-conversion-tobool"
     5  description: |-
     6    The tobool function converts a value to boolean.
     7  ---
     8  
     9  # `tobool` Function
    10  
    11  -> **Note:** This page is about Terraform 0.12 and later. For Terraform 0.11 and
    12  earlier, see
    13  [0.11 Configuration Language: Interpolation Syntax](../../configuration-0-11/interpolation.html).
    14  
    15  `tobool` converts its argument to a boolean value.
    16  
    17  Explicit type conversions are rarely necessary in Terraform because it will
    18  convert types automatically where required. Use the explicit type conversion
    19  functions only to normalize types returned in module outputs.
    20  
    21  Only boolean values and the exact strings `"true"` and `"false"` can be
    22  converted to boolean. All other values will produce an error.
    23  
    24  ## Examples
    25  
    26  ```
    27  > tobool(true)
    28  true
    29  > tobool("true")
    30  true
    31  > tobool("no")
    32  Error: Invalid function argument
    33  
    34  Invalid value for "v" parameter: cannot convert "no" to bool: only the strings
    35  "true" or "false" are allowed.
    36  
    37  > tobool(1)
    38  Error: Invalid function argument
    39  
    40  Invalid value for "v" parameter: cannot convert number to bool.
    41  ```