provider::terraform::decode_tfvars Function

provider::terraform::decode_tfvars is a rarely-needed function which takes a string containing the content of a .tfvars file and returns an object describing the raw variable values it defines.

To use this function, your module must declare a dependency on the built-in terraform provider, which contains this function:

terraform {
  required_providers {
    terraform = {
      source = "terraform.io/builtin/terraform"
    }
  }
}

Elsewhere in your module you can then call this function:

provider::terraform::decode_tfvars(
  <<EOT
    example = "Hello!"
  EOT
)
    example = "Hello!"
  EOT
)

The call above would produce an object value like the following:

{
  example = "Hello!"
}

Result Types

When interpreting a .tfvars file, Terraform CLI normally uses the variable declarations from the related module to find a target type to convert the definitions for use in the module.

tfvarsdecode does not have access to that type information, and so the result always uses the most general type that a particular syntax could represent. The supported value types for attributes of the result are:

If you need to interpret object or tuple values as collection types, use the type conversion functions to convert the returned values. There is no way to represent list, set, or map values directly in the .tfvars format.