Skip to content

Variables and var files

Variable values set a configuration’s inputs without changing its .tf files. Give them to a start verb for one run, or to open to keep them for the workspace while it is open. terraform.tfvars, *.auto.tfvars and TF_VAR_ variables load on their own, as they do for any Turf™ run.

✦Your agentin Claude Code
You
Deploy kind-crd with cr_message set to “Hello from staging”.
Agent
  • up→awaiting_plan
  • plan→awaiting_approval

Plan: 0 to add, 1 to change, 0 to destroy.

~ kubernetes_manifest.instance
manifest.spec.message: "Hello from Turf" → "Hello from staging"

That value holds for this run only: the next up without it plans the default back. To keep it, I can put it in terraform.tfvars, which loads on its own. Ready to apply these changes?

You
Yes, and put it in terraform.tfvars.
Agent
  • apply→converged

Applied: 1 changed. Then I wrote cr_message = "Hello from staging" to terraform.tfvars. I waited until after the apply: terraform.tfvars loads on its own, so writing it between the plan and the apply would have made the plan stale. The next up plans no change.

illustrative · the shape of a session, not a transcript

Say the values, or name the file: “deploy with region eu-west-1”, “use env/staging.tfvars”. The agent passes them as var or var_file. When init reports a required variable that nothing supplies, the agent asks you for it. Setting variable values is deployment, not authoring: the configuration does not change, though the agent writes a line in a .tfvars file when you ask it to.

TF_VAR_name variables come from the MCP server’s environment: in most clients, the env block of the server’s entry in the client’s configuration.

For one run. A start verb’s var and var_file (on up, destroy, refresh, import or invoke) hold for that run’s rounds and are never kept. They are laid over the values open was given, name by name. The read tools (state_list, output, show) use open’s values, not these.

For the workspace. open keeps its own var and var_file for the workspace while it is open: in the server’s memory only, never written down, never shown back (status lists the names). Every later tool on the workspace reads the state with them, and each run lays its own values over them. Opening the workspace again with var or var_file replaces them. They last as long as the session: when it ends, the workspace closes. A value the backend block reads, and a state-encryption passphrase, go to open.

What the engine keeps. The engine pins a run’s values with the run. When an up converges, the engine keeps that run’s configuration with its values, sensitive ones included, so it can read objects between runs. The next converged up replaces the copy, and a converged destroy removes it. Ephemeral variables are never kept. See Drift.

Loaded on their own. terraform.tfvars and *.auto.tfvars in the configuration directory, and TF_VAR_ variables in the MCP server’s environment. TF_VAR_ never comes from mise.

What init reports. variables[] lists what the configuration declares, never resolved values. required means the declaration has no default, not that no value exists: the environment or a .tfvars file may still supply one. There are no interactive prompts at plan, so the agent asks you for a required value nothing supplies. A module’s source or version that reads a variable takes its value from init’s own var, for that init only; every plan installs the modules again, so give the same value to open as well.

How a value is read. A string is the raw text a -var carries, parsed by the declaration’s type: "2" is a number for a number variable. Any other JSON value is passed as its HCL literal. A relative var_file path is relative to the configuration directory.

Values never make a plan stale. var, var_file and TF_VAR_ values are pinned with the run. An edit to an auto-loaded .tfvars file between plan and apply does make the plan stale: the run ends stale and nothing is applied.

Differs from Terraform®. tofu takes -var on every command. Here open’s values serve every later tool on the workspace, as an exported TF_VAR_ serves a shell. Within one call, var always wins over var_file; there is no interleaving of -var and -var-file.

Highest first. A name set higher wins.

Source Kept for
The start verb’s var This run
The start verb’s var_file, in order This run
open’s var The workspace, while it is open
open’s var_file, in order The workspace, while it is open
terraform.tfvars and *.auto.tfvars Loaded at every use
TF_VAR_name in the MCP server’s environment Loaded at every use

Turf™ is a trademark of Turf LLC. Terraform® is a trademark of HashiCorp. Ansible® is a trademark of Red Hat, LLC, registered in the United States and other countries. Helm®, Kubernetes®, Prometheus® and OpenTelemetry® are registered trademarks, and Jaeger™ is a trademark, of the Linux Foundation. OpenTofu® and Model Context Protocol® are registered trademarks of LF Projects, LLC. All other trademarks are the property of their respective owners. Turf is not affiliated with, endorsed by, or sponsored by HashiCorp, IBM, Red Hat, the Linux Foundation, LF Projects or the OpenTofu project.

© 2026 Turf LLC. Free for individuals, education and small businesses within the Community limits, under the Turf Community Edition License 1.0. Government and larger organizations need a commerciallicense.turf.build · Discord ·GitHub