SkillAgentSearch skills...

Tofuenv

OpenTofu version manager

Install / Use

/learn @tofuutils/Tofuenv

README

<!-- BADGES -->

OpenSSF Best Practices Github release Contributors maintenance status

<h1 align="center">tofuenv</h1> <h3 align="center"> <a href="https://opentofu.org/">OpenTofu</a> version manager inspired by <a href="https://github.com/tfutils/tfenv">tfenv</a> </h3>

Table of Content

<div align="center"> <a href="#important-notice">Important Notice</a> • <a href="#supported-os">Supported OS</a> • <a href="#installation">Installation</a> • <a href="#install-dependencies">Install dependencies</a> • <a href="#usage">Usage</a> • <a href="#environment-variables">Environment Variables</a> • <a href="#upgrading">Upgrading</a> • <a href="#uninstalling">Uninstalling</a> • <a href="#contributing">Contributing</a> • <a href="#community">Community</a> • <a href="#authors">Authors</a> • <a href="#license">License</a> </div>

Important Notice

Many people have asked about Terraform support, and we are finally ready to announce a successor for tfenv and tofuenv: <a href="https://github.com/tofuutils/tenv">tenv </a> 🚀 written in Golang. tenv is able to handle Terraform binaries as well as OpenTofu binaries. 🎉

Please contribute to <a href="https://github.com/tofuutils/tenv">tenv </a> and award us stars⭐.

Supported OS

Currently, tofuenv supports the following operating systems:

<details> <summary><b>macOS</b></summary> <ul> <li>64bit</li> <li>Arm (Apple Silicon)</li> </ul> </details> <details> <summary><b>Linux</b></summary> <ul> <li>64bit</li> <li>Arm</li> </ul> </details> <details> <summary><b>Windows</b> (Only tested in git-bash - currently presumed failing due to symlink issues in git-bash)</summary> <ul> <li>64bit</li> </ul> </details>

Installation

Automatic

<details><summary><b>Install via Homebrew</b></summary>
  brew tap tofuutils/tap
  brew install tofuenv
</details> <details><summary><b>Install via Arch User Repository (AUR)</b></summary>
git clone https://aur.archlinux.org/tofuenv.git
cd tofuenv
makepkg -si
</details> <details><summary><b>Install via Arch User Repository (AUR) via yay</b></summary>
yay --sync tofuenv
</details>

Manual

<details><summary><b>Linux and MacOS</b></summary>
  1. Check out tofuenv into any path (here is ${HOME}/.tofuenv)
git clone --depth=1 https://github.com/tofuutils/tofuenv.git ~/.tofuenv
  1. Add ~/.tofuenv/bin to your $PATH any way you like

bash:

echo 'export PATH="$HOME/.tofuenv/bin:$PATH"' >> ~/.bash_profile

zsh:

$ echo 'export PATH="$HOME/.tofuenv/bin:$PATH"' >> ~/.zprofile

For WSL users:

echo 'export PATH=$PATH:$HOME/.tofuenv/bin' >> ~/.bashrc

OR you can make symlinks for tofuenv/bin/* scripts into a path that is already added to your $PATH (e.g. /usr/local/bin) OSX/Linux Only!

ln -s ~/.tofuenv/bin/* /usr/local/bin

On Ubuntu/Debian touching /usr/local/bin might require sudo access, but you can create ${HOME}/bin or ${HOME}/.local/bin and on next login it will get added to the session $PATH or by running . ${HOME}/.profile it will get added to the current shell session's $PATH.

mkdir -p ~/.local/bin/
. ~/.profile
ln -s ~/.tofuenv/bin/* ~/.local/bin
which tofuenv
</details> <details><summary><b>Windows</b></summary>
  1. Install Git-Bash
winget install --id Git.Git -e --source winget
  1. Launch git-bash environment, execute (keep the quotes):
"C:\Program Files\Git\bin\sh.exe"
  1. Check out tofuenv into any path (here is ${HOME}/.tofuenv)
git clone --depth=1 https://github.com/tofuutils/tofuenv.git ~/.tofuenv
  1. Add ~/.tofuenv/bin to your $PATH
echo 'export PATH=$PATH:$HOME/.tofuenv/bin' >> ~/.bashrc
  1. Relaunch git-bash environment for the changes to be applied (you can do it via exit command).

  2. Verify installation by executing:

which tofuenv
</details>

Install dependencies

Install jq (required) and GnuPG (optional, in case you want to enable GPG verification during OpenTofu installation)

<details><summary><b>MacOs</b></summary>
brew install jq gnupg grep
</details> <details><summary><b>Linux</b></summary>
sudo apt-get update -y
sudo apt-get install -y jq gnupg
</details> <details><summary><b>Windows</b> (git-bash)</summary> Install jq package into git-bash default installation folder:
curl -L -o /usr/bin/jq.exe https://github.com/jqlang/jq/releases/latest/download/jq-win64.exe
</details>

Usage

tofuenv install [version]

Install a specific version of OpenTofu.

If no parameter is passed, the version to use is resolved automatically via TOFUENV_TOFU_VERSION environment variable or .opentofu-version files, in that order of precedence, i.e. TOFUENV_TOFU_VERSION, then .opentofu-version. The default is latest if none are found.

If a parameter is passed, available options:

  • x.y.z Semver 2.0.0 string specifying the exact version to install
  • latest:<regex> is a syntax to install latest version matching regex (used by grep -e)
  • latest-allowed is a syntax to scan your OpenTofu files to detect which version is maximally allowed.
  • min-required is a syntax to scan your OpenTofu files to detect which version is minimally required.

Options will be available after first stable release:

  • latest is a syntax to install latest stable version

See required_version docs. Also see min-required & latest-allowed section below.

$ tofuenv install 1.6.0-rc1 
$ tofuenv install latest:^1.6
$ tofuenv install latest-allowed
$ tofuenv install min-required

If shasum is present in the path, tofuenv will verify the download against OpenTofu published sha256 hash.

You can opt-in to using GnuPG tools for GPG signature verification:

echo 'trust-tofuenv: yes' > ${TOFUENV_INSTALL_DIR}/use-gpgv
tofuenv install

Where TOFUENV_INSTALL_DIR is for example, ~/tofuenv or /opt/homebrew/Cellar/tofuenv/<version>

The trust-tofuenv directive means that verification uses a copy of the OpenTofu GPG key found in the tofuenv repository. Skipping that directive means that the OpenTofu key must be in the existing default trusted keys. Use the file ${TOFUENV_INSTALL_DIR}/use-gnupg to instead invoke the full gpg tool and see web-of-trust status; beware that a lack of trust path will not cause a validation failure. Default gpg/gpgv command can be overridden by adding binary directive to use-gpgv/use-gnupg file, ex.:

echo 'binary: gpgv --keyring ./path/to/gpg/opentofu.gpg' > ${TOFUENV_INSTALL_DIR}/use-gpgv
tofuenv install

For now keybase tool GPG signature verification is not supported by OpenTofu. This verification mechanism will be added after support is added by OpenTofu.

.opentofu-version

If you use a .opentofu-version file, tofuenv install (no argument) will install the version written in it.

<a name="min-required"></a>

min-required & latest-allowed

Please note that we don't do semantic version range parsing but use first ever found version as the candidate for minimally required one. It is up to the user to keep the definition reasonable. I.e.

// this will detect 0.12.3
terraform {
  required_version  = "<0.12.3, >= 0.10.0"
}
// this will detect 0.10.8 (the latest 0.10.x release)
terraform {
  required_version  = "~> 0.10.0, <0.12.3"
}

Environment Variables

TOFUENV

<details id="TOFUENV_GITHUB_TOKEN"><summary><b>TOFUENV_GITHUB_TOKEN</b></summary><br>

String (Default: "")

Specify GitHub token. Because of OpenTofu binares placed in the GitHub you may encounter with rate limit problem. Using a personal access token dramatically increases rate limit. GitHub Rate limits for the REST API

</details> <details id="TOFUENV_ARCH"><summary><b>TOFUENV_ARCH</b></summary><br>

String (Default: amd64)

Specify architecture. Architecture other than the default amd64 can be specified with the TOFUENV_ARCH environment variable

Note: Default changes to arm64 for versions that have arm64 builds available when $(uname -m) matches aarch64* | arm64*

TOFUENV_ARCH=arm64 tofuenv install 0.7.9
</details> <details id="TOFUENV_AUTO_INSTALL"><summary><b>TOFUENV_AUTO_INSTALL</b></summary><br>

String (Default: true)

Should tofuenv automatically install tofu if the version specified by defaults or a .opentofu-version file is not currently installed.

Example: if auto installation is enabled, the version will be installed.

TOFUENV_AUTO_INSTALL=true tofu use <version that is not yet installed>

Example: use 1.6.0-beta3 version that is not installed, and auto installation is disabled.

$ TOFUENV_AUTO_INSTALL=false tofuenv use 1.6.0-beta3
No installed versions of opentofu matched '^1.6.0-beta3$'. TOFUENV_AUTO_INSTALL is set to false, so exiting.
</details> <details id="TOFUENV_CURL_OUTPUT"><summary><b>TOFUENV_CURL_OUTPUT</b></summary><br>

Integer (Default: 2)

Set the mechanism used for displaying download progress when downloading tofu versions from the remote server.

  • 2: v1 Behaviour: Pass -# to curl
  • 1: Use curl default
  • 0: Pass -s to curl </d
View on GitHub
GitHub Stars225
CategoryDevelopment
Updated22d ago
Forks7

Languages

Shell

Security Score

100/100

Audited on Mar 11, 2026

No findings