Skip to content

Variables Reference

Variable declarations live in the configuration (variable {} blocks); variable values come with open and each plan command and are never written to disk by Turf. Supplying values is deployment (skill_deployment); this file is about declaring them and wiring secrets.

Lowest to highest precedence, as in Terraform:

  1. the variable block’s default
  2. TF_VAR_<name> — this server’s environment (the MCP client’s env block), parsed literally for primitive types and as an HCL expression otherwise
  3. auto-loaded files: terraform.tfvars, terraform.tfvars.json, then *.auto.tfvars / *.auto.tfvars.json in one lexical pass
  4. open’s var_file, in listed order, then open’s var — kept for the workspace while it is open
  5. the plan command’s var_file (tofu -var-file), in listed order
  6. the plan command’s var (tofu -var) — wins. A string is the raw text a -var carries; any other JSON value is its HCL literal

A plan command’s values win over open’s name by name, whichever of its rungs carries the name. The plan commands are up, destroy, refresh, import and invoke. The values one is given hold for that convergence — every round uses them, and apply never asks again — and are never kept; open’s serve every tool on the workspace (the read tools derive the backend and the state encryption with them) until it is closed. Nothing is persisted.

Differs from Terraform: no -var/-var-file interleaving (var always wins over var_file within a call), open keeps its values for the workspace, and no prompting at plan time. The one prompt is at init: a required variable a module source needs is asked of the user when nothing supplies it (or given as init’s var), never a sensitive one.

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.

init’s variables[] are declarations, never values: required means the block has no default, not that nothing supplies it. A sensitive or ephemeral variable’s default is reported as __cty_sensitive__. A plan missing a required value fails, naming the variable.

Every declared variable is finalized as Terraform does: optional(type, default) defaults, conversion to the declared type, nullable = false (an explicit null takes the default), and validation {} rules.

Validation timing. A rule is checked at plan. One 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 convergence 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, which are decided before anything is applied.

  • Provider credentials → a variable with sensitive = true (and ephemeral = true when it only feeds provider blocks and write-only arguments), referenced as var.x in the provider block. Better still, leave them to the environment providers run with (skill_deployment → references/credentials.md).
  • Backend credentials → out of the backend block; passed in open’s backend_config.
  • A secret a resource needs → only a write-only argument.

An ephemeral = true variable’s value may flow into provider configuration, ephemeral module inputs and outputs, and a resource’s write-only arguments — never into any other resource or data-source attribute, a count/for_each, or a root output. Stored plan variables record it by name only. A convergence holds the values its plan command was given for every round’s plan and apply, which is how Turf meets the Terraform “re-supply ephemeral values at apply” rule.

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 (conventionally *_wo).

variable "db_password" {
type = string
ephemeral = true
}
resource "example_database" "db" {
password_wo = var.db_password # the value arrives with up's var, for this convergence only
}
  • Pass it as an expression, never a literal: a literal is a secret written into the directory and every plan.
  • 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 requires-replace: rotating a secret usually reads as a 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, say so rather than working around it.

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.

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