tf

Less verbose, more shell-friendly and LLM-friendly Terraform and OpenTofu.
| Better this: | Than this: |
|---|
 |  |
The original Terraform and OpenTofu are abusively oververbosed. The tf
wrapper runs either of them and makes it more CLI-friendly:
- removes unnecessary output
- adds own colored progress indicator
- provides an extra compact mode
- allows to use of multiple arguments when original command doesn't support it
- adds automatically quotes for indexed resources (
xargs friendly)
- generates a log file when
TF_OUTPUT_PATH environment variable is used
tf is optimized for LLM coding agents too: its output takes a fraction of
the tokens of the output of Terraform or OpenTofu, and its resource addresses
need no shell quoting. Under an agent the token-saving mode is on by default,
without colors and without the progress indicator (see
Coding agents).
Install
Download from releases. Put anywhere
in the $PATH.
Verify
Since v2.14.1 every release carries a build provenance attestation and an SPDX
SBOM (*.sbom.json) for each binary. Verify a downloaded binary with
GitHub CLI:
gh attestation verify tf-linux-amd64 --repo dex4er/tf
asdf
Install with asdf:
asdf plugin-add tf https://github.com/dex4er/asdf-tf.git
asdf install tf latest
asdf global tf latest
mise
Install with mise-en-place from the releases, which
verifies the build provenance attestation of the binary:
mise use -g github:dex4er/tf
Homebrew
Install with homebrew:
brew install --cask dex4er/tap/tf
Since v2.14.1 the tap ships a cask rather than a formula, on both macOS and
Linux. If you installed the formula earlier, brew upgrade migrates you over
automatically.
Zsh
With Zsh noglob should be used to prevent errors when indexed parameters
are arguments for tf command.
Add to ~/.zshenv:
alias tf='noglob tf'
You can re-use the completion of the Oh My Zsh plugin dedicated to the
original Terraform, whether tf runs Terraform or OpenTofu:
compdef _terraform tf
Usage
tf init
tf plan
tf apply
tf list
tf show
etc...
You can combine commands, ie.:
tf apply $(tf list | grep aws_vpc)
tf list | grep data.aws_region.current | xargs tf refresh
tf list | grep random_password | xargs tf rm
tf list | grep aws_subnet | xargs tf show
tf list | grep module.one | while read r; do echo tf mv $r ${r/module.one./module.two.}; done | bash -x
tf list | fzf | xargs tf show | highlight -O xterm256 --syntax terraform
It is recommended to use $() rather than xargs for tf apply or tf destroy because these commands are interactive.
For not recognized commands tf passes all arguments to terraform or
tofu command.
The options take their values after = or as the next argument, as -out tfplan or -var name=value. The addresses of -replace, -exclude and
-invoke get their quotes back as those of -target do.
Terraform or OpenTofu
tf runs tofu if a .opentofu-version file exists in the current
directory or in one of the parent directories and there was no
.terraform-version file in a directory nearer to the current one. Otherwise
it runs terraform.
The command might be set explicitly with TERRAFORM_PATH environment
variable, ie.:
export TERRAFORM_PATH=tofu
Coding agents
When tf runs under a coding agent, it turns the colors off and hides the
progress indicator, as with -no-color -quiet. It recognizes the agent by the
AI_AGENT environment variable, or by the variables of Claude Code, Codex,
opencode and GitHub Copilot. TF_AGENT=true or TF_AGENT=false overrides the
detection, and the options of the command line still win.
The NO_COLOR environment variable turns the colors off too.
tf apply