Variables
Variable declarations live in the configuration, in variable blocks. Variable values come with
open and each plan command, and Turf™ never writes them to disk. This page is about declaring
variables and wiring secrets; supplying values is deployment, covered in
Variables and var files and Variables and TF_VAR_.
Declare a variable
Section titled “Declare a variable”variable "region" { type = string default = "eu-west-1"}
variable "instance_count" { type = number validation { condition = var.instance_count >= 1 && var.instance_count <= 10 error_message = "instance_count must be between 1 and 10." }}
variable "api_token" { type = string sensitive = true}Every declared variable is finalized as Terraform® does it: optional(type, default) defaults,
conversion to the declared type, nullable = false (an explicit null takes the default), and
validation rules.
What init reports
Section titled “What init reports”init’s variables[] are declarations, never values. required means the block has no default,
not that nothing supplies a value. A sensitive or ephemeral variable’s default is reported as
__cty_sensitive__. A plan missing a required value fails, naming the variable.
Validation
Section titled “Validation”A rule is checked at plan. A rule whose condition reads a value not yet known is a warning at plan, and is decided later:
- A rule that reads something this round applies is decided after the apply. Differs from
Terraform: if it fails then, the round has already applied, all of it, and the run ends
failed, naming the rule. - A rule that reads a deferred address is decided in the round that converges.
Prefer rules over the variable’s own value. Those are decided before anything is applied.
Secrets
Section titled “Secrets”- Provider credentials: a variable with
sensitive = true, plusephemeral = truewhen it only feeds provider blocks and write-only arguments, referenced asvar.xin theproviderblock. Better still, leave them to the engine’s environment, or to a variable the server sends by name. - Backend credentials: out of the
backendblock, passed inopen’sbackend_config. - A secret a resource needs: only a write-only argument.
Ephemeral variables
Section titled “Ephemeral variables”An ephemeral = true variable’s value may flow into provider configuration, ephemeral module inputs
and outputs, and a resource’s write-only arguments. It never flows into any other resource or data
source attribute, a count or for_each, or a root output. Stored plan variables record it by name
only. A run holds the values its plan command was given for every round’s plan and apply, which is
how Turf meets the Terraform rule that ephemeral values are supplied again at apply.
A child module’s output may be ephemeral = true, so a module can hand its caller a
secret without the value reaching state or the saved plan. A root output may not.
Write-only arguments
Section titled “Write-only arguments”A write-only argument is the only way a secret reaches a managed resource without being kept. The
provider receives it on every request and returns null, so state, the plan and the directory never
see it. provider_describe marks it write_only: true; by convention its name ends in _wo.
variable "db_password" { type = string ephemeral = true}
resource "example_database" "db" { password_wo = var.db_password # arrives with up's var, for this run only}- Pass it as an expression, never a literal: a literal is a secret written into the directory and every plan.
- Rotation usually reads as a replacement. The value is null on both sides of every plan, so nothing shows that it changed. A provider signals a change by marking the write-only path as requiring replacement.
- A provider that echoes a non-null value back for one is refused outright.
- A secret routed through an ordinary attribute or a data source is kept in state forever. If the provider has no write-only argument for the field, your agent says so rather than working around it.
Module inputs
Section titled “Module inputs”A module call must pass exactly the inputs its child module declares. The plan is refused, naming the
call and every offending input at once, when a required input (no default in the child) is unset, and
when an argument names no variable the child declares. A misspelled input shows up as both, so you see
namee beside the name it failed to set. Neither is deferred.
A module call reaches an ephemeral value by referencing it (api_token = var.api_token), so the
reference is in the file and the value arrives from the plan command each round.
Where a value comes from
Section titled “Where a value comes from”Lowest to highest precedence, as in Terraform:
| Source | |
|---|---|
| 1 | the variable block’s default |
| 2 | TF_VAR_<name> from the MCP server’s environment |
| 3 | terraform.tfvars, terraform.tfvars.json, then *.auto.tfvars and *.auto.tfvars.json |
| 4 | open’s var_file, in listed order, then open’s var |
| 5 | the plan command’s var_file, in listed order |
| 6 | the plan command’s var: wins |
As in Terraform, a var naming an undeclared variable is an error, a variables file’s entry for one
warns, and a TF_VAR_ for one is ignored.
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