.tfvars files directly inside a
forma. Existing variable files from a Terraform
or OpenTofu codebase can drive a formae deployment without conversion or
duplication, so the same inputs stay shared between both tools while you migrate.
The terraform.readTFVars() function parses an HCL-format .tfvars file and
returns its variables as a Pkl Dynamic, so you read values with dot notation.
Read a tfvars file
1
Import the terraform extension
Add the import alongside your other Pkl imports at the top of the forma:
2
Read the file
Bind the parsed values to a local. The path is resolved relative to the
forma file’s directory, and absolute paths also work:
3
Access values with dot notation
Given this the values come through as:
prod.tfvars:Example forma
This forma readsenv/prod.tfvars and uses its values to set a
target region and interpolate a queue name:
--simulate to preview the plan without applying, or --yes to skip the
confirmation prompt.
Supported types
Values are mapped from HCL to Pkl types as follows:What is supported
readTFVars reads HCL-format .tfvars files. The .tfvars.json format is not
supported, and the file extension must be .tfvars. Values must be literals:
variable references and function calls inside the file are not evaluated.See also
- Forma: the file that declares your infrastructure.
- Values: how formae resolves values in a forma.
- Create a target: configure the cloud account and region a forma deploys to.

