### OpenTofu installation output example Source: https://context7.com/tofuutils/tenv/llms.txt Example output demonstrating the process of installing a specific OpenTofu version. ```text # Expected output for an exact install: # Installing OpenTofu 1.6.0 # Fetching release information from https://api.github.com/repos/opentofu/opentofu/releases/tags/v1.6.0 # Downloading https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_linux_amd64.zip # ... # Installation of OpenTofu 1.6.0 successful ``` -------------------------------- ### Install tenv module Source: https://github.com/tofuutils/tenv/blob/main/TENV_AS_LIB.md Use 'go get' to install the latest version of the tenv library. This command fetches the module and updates your project's dependencies. ```console go get -u github.com/tofuutils/tenv/v4@latest ``` -------------------------------- ### Install Cosign via Go (Windows) Source: https://github.com/tofuutils/tenv/blob/main/README.md Installs the cosign tool on Windows using the Go toolchain. Requires Go to be installed and in your PATH. ```sh go install github.com/sigstore/cosign/v2/cmd/cosign@latest ``` -------------------------------- ### Example of tenv concurrent installation retry behavior Source: https://github.com/tofuutils/tenv/blob/main/README.md Demonstrates how tenv handles concurrent installations by retrying when a lock file is already in use. This ensures safe parallel operations. ```console $ tenv tofu install 1.6.0 & tenv tofu install 1.6.1 [1] Installing OpenTofu 1.6.0 [2] can not write .lock file, will retry: file already exists [2] can not write .lock file, will retry: file already exists [1] Installation of OpenTofu 1.6.0 successful [2] Installing OpenTofu 1.6.1 [2] Installation of OpenTofu 1.6.1 successful ``` -------------------------------- ### Install tenv on Ubuntu/Debian Source: https://context7.com/tofuutils/tenv/llms.txt Install tenv on Ubuntu or Debian systems by downloading the latest .deb package and installing it with dpkg. ```sh LATEST_VERSION=$(curl --silent https://api.github.com/repos/tofuutils/tenv/releases/latest | jq -r .tag_name) curl -O -L "https://github.com/tofuutils/tenv/releases/latest/download/tenv_${LATEST_VERSION}_amd64.deb" sudo dpkg -i "tenv_${LATEST_VERSION}_amd64.deb" ``` -------------------------------- ### Set OpenTofu Remote, Install Mode, and List URL Source: https://github.com/tofuutils/tenv/blob/main/README.md Configure OpenTofu to use a remote mirror, install directly, and fetch release listings from the GitHub API. This setup is beneficial when the mirror provides direct download links but release information is best obtained from the official API. ```console TOFUENV_REMOTE=https://artifactory.example.com/artifactory/github TOFUENV_INSTALL_MODE=direct TOFUENV_LIST_URL=https://api.github.com/repos/opentofu/opentofu/releases ``` -------------------------------- ### Setup Oh My Zsh completion Source: https://github.com/tofuutils/tenv/blob/main/README.md Installs zsh shell completion for tenv specifically for Oh My Zsh. Ensure the completions folder is in your $fpath. ```sh tenv completion zsh > ~/.oh-my-zsh/completions/_tenv print -l $fpath ``` -------------------------------- ### Install tenv via WinGet Source: https://context7.com/tofuutils/tenv/llms.txt Install tenv on Windows using the WinGet package manager. ```sh winget install Tofuutils.Tenv ``` -------------------------------- ### Setup bash shell completion Source: https://github.com/tofuutils/tenv/blob/main/README.md Installs bash shell completion for tenv by sourcing a generated completion file into your .bashrc. ```sh tenv completion bash > ~/.tenv.completion.bash echo "source \ $HOME/.tenv.completion.bash" >> ~/.bashrc ``` -------------------------------- ### Install tenv via Snap Source: https://context7.com/tofuutils/tenv/llms.txt Install tenv on Linux systems using the Snap package manager. ```sh snap install tenv ``` -------------------------------- ### Setup powershell completion Source: https://github.com/tofuutils/tenv/blob/main/README.md Installs powershell shell completion for tenv by piping the output of the completion command to Invoke-Expression. ```powershell tenv completion powershell | Out-String | Invoke-Expression ``` -------------------------------- ### Setup fish shell completion Source: https://github.com/tofuutils/tenv/blob/main/README.md Installs fish shell completion for tenv by sourcing a generated completion file into your fish config. ```sh tenv completion fish > ~/.tenv.completion.fish echo "source \ $HOME/.tenv.completion.fish" >> ~/.config/fish/config.fish ``` -------------------------------- ### New Guide Changelog Entry Source: https://github.com/tofuutils/tenv/blob/main/contributing/changelog-process.md Use the `release-note:new-guide` header for new full-length documentation guides. ```markdown ```release-note:new-guide How To Get Started With Tool X ``` ``` -------------------------------- ### Install OpenTofu using latest-allowed strategy Source: https://context7.com/tofuutils/tenv/llms.txt Scans project files for OpenTofu version requirements and installs the highest allowed version. ```sh # Scan .tf files and install the maximally allowed version tenv tofu install latest-allowed ``` -------------------------------- ### Install Tenv After Verification Source: https://github.com/tofuutils/tenv/blob/main/README.md Installs tenv using dnf if signature and checksum verifications pass. This ensures the integrity of the downloaded package before installation. ```bash if [ "$TENV_SIG_CHECK" -eq "0" ] && [ "$TENV_ASSET_CHECK" -eq "0" ] && shasum -a 256 -c "tenv_${LATEST_VERSION}_checksums.txt" --ignore-missing then dnf install "tenv_${LATEST_VERSION}_amd64.rpm" -y tenv --version else echo "Signature verification and/or checksum checks failed!" fi ``` -------------------------------- ### Install Tenv via APK after Cloudsmith Setup (Alpine) Source: https://github.com/tofuutils/tenv/blob/main/README.md Installs the tenv package on Alpine Linux using apk after the Cloudsmith repository has been set up. ```sh apk add tenv ``` -------------------------------- ### Tenv.Install and Tenv.InstallMultiple Source: https://context7.com/tofuutils/tenv/llms.txt Install one or multiple specific versions of a tool programmatically. ```APIDOC ## Go Library — `Tenv.Install` and `Tenv.InstallMultiple` Install one or multiple specific versions programmatically. ### Example Usage ```go package main import ( "context" "fmt" "github.com/tofuutils/tenv/v4/config/cmdconst" "github.com/tofuutils/tenv/v4/versionmanager/tenvlib" ) func main() { tenv, err := tenvlib.Make(tenvlib.DisableDisplay) if err != nil { fmt.Println("init failed:", err) return } ctx := context.Background() // Install a single version if err = tenv.Install(ctx, cmdconst.TofuName, "1.6.0"); err != nil { fmt.Println("install failed:", err) return } // Install multiple versions in a single locked batch if err = tenv.InstallMultiple(ctx, cmdconst.TerraformName, []string{"1.6.6", "1.7.0", "1.7.2"}); err != nil { fmt.Println("batch install failed:", err) return } fmt.Println("All versions installed successfully") } ``` ``` -------------------------------- ### Install Tenv via Scoop (Windows) Source: https://github.com/tofuutils/tenv/blob/main/README.md Installs the tenv package on Windows using the Scoop package manager. ```console scoop install tenv ``` -------------------------------- ### Setup zsh shell completion Source: https://github.com/tofuutils/tenv/blob/main/README.md Installs zsh shell completion for tenv by sourcing a generated completion file into your .zshrc. ```sh tenv completion zsh > ~/.tenv.completion.zsh echo "source \ $HOME/.tenv.completion.zsh" >> ~/.zshrc ``` -------------------------------- ### Install tenv on NixOS via nix-env Source: https://github.com/tofuutils/tenv/blob/main/README.md Installs tenv using the nix-env command on NixOS. ```sh nix-env -iA nixos.tenv ``` -------------------------------- ### Install tenv via apt Source: https://github.com/tofuutils/tenv/blob/main/README.md Installs the tenv package using the apt package manager after setting up the Cloudsmith repository. ```sh curl -1sLf 'https://dl.cloudsmith.io/public/tofuutils/tenv/cfg/setup/bash.deb.sh' | sudo bash sudo apt install tenv ``` -------------------------------- ### List Local, Remote, and Installed Versions with Tenv Go Library Source: https://context7.com/tofuutils/tenv/llms.txt Use `ListLocal`, `ListRemote`, and `LocallyInstalled` to query tool versions. Ensure the tenv library is initialized with `tenvlib.Make`. ```go package main import ( "context" "fmt" "github.com/tofuutils/tenv/v4/config/cmdconst" "github.com/tofuutils/tenv/v4/versionmanager/tenvlib" ) func main() { tenv, err := tenvlib.Make(tenvlib.DisableDisplay) if err != nil { fmt.Println("init failed:", err) return } ctx := context.Background() // List local versions with last-use date (ascending order) local, err := tenv.ListLocal(ctx, cmdconst.TofuName, false) if err != nil { fmt.Println("list local failed:", err) return } for _, dv := range local { fmt.Printf(" %s (last used: %s)\n", dv.Version, dv.UseDate.Format("2006-01-02")) } // List remote versions (descending order) remote, err := tenv.ListRemote(ctx, cmdconst.TerraformName, true) if err != nil { fmt.Println("list remote failed:", err) return } fmt.Println("Latest remote Terraform:", remote[0]) // Get a set of locally installed versions installed, err := tenv.LocallyInstalled(ctx, cmdconst.TerragruntName) if err != nil { fmt.Println("locally installed failed:", err) return } if _, ok := installed["0.55.1"]; ok { fmt.Println("Terragrunt 0.55.1 is installed") } } ``` -------------------------------- ### Setup Cloudsmith Repository for Alpine Linux Source: https://github.com/tofuutils/tenv/blob/main/README.md Sets up the Cloudsmith repository for Tofuutils/tenv on Alpine Linux. This is a prerequisite for installing tenv via apk from Cloudsmith. ```sh sudo apk add --no-cache bash curl -1sLf 'https://dl.cloudsmith.io/public/tofuutils/tenv/cfg/setup/bash.alpine.sh' | sudo bash ``` -------------------------------- ### Install OpenTofu exact version Source: https://context7.com/tofuutils/tenv/llms.txt Installs a specific version of OpenTofu using its exact semantic version string. ```sh # Install exact version tenv tofu install 1.6.0 ``` -------------------------------- ### List installed OpenTofu versions verbosely Source: https://context7.com/tofuutils/tenv/llms.txt Lists all locally installed OpenTofu versions, indicating the active version and its source. ```sh tenv tofu list -v # * 1.6.0 (set by /home/user/.tenv/OpenTofu/version) # 1.6.1 # found 2 OpenTofu version(s) managed by tenv. ``` -------------------------------- ### Install tenv via Homebrew Source: https://context7.com/tofuutils/tenv/llms.txt Use Homebrew to install tenv on macOS or Linux systems. ```sh brew install tenv ``` -------------------------------- ### Install Cosign via RPM Package (Linux) Source: https://github.com/tofuutils/tenv/blob/main/README.md Installs the cosign tool on Linux distributions that use RPM packages. This script fetches the latest version and installs it. ```sh LATEST_VERSION=$(curl https://api.github.com/repos/sigstore/cosign/releases/latest | jq -r .tag_name | tr -d "v") curl -O -L "https://github.com/sigstore/cosign/releases/latest/download/cosign-${LATEST_VERSION}-1.x86_64.rpm" sudo rpm -ivh cosign-${LATEST_VERSION}-1.x86_64.rpm ``` -------------------------------- ### Install Cosign via Homebrew (MacOS) Source: https://github.com/tofuutils/tenv/blob/main/README.md Installs the cosign tool on macOS using the Homebrew package manager. Ensure Homebrew is installed first. ```sh brew install cosign ``` -------------------------------- ### Set OpenTofu Remote, Install, and List Mode Source: https://github.com/tofuutils/tenv/blob/main/README.md Configure OpenTofu to use a remote mirror, install directly from generated URLs, and parse HTML for release listings. This is useful for mirrors that don't provide a release index but do host files in a predictable structure. ```console TOFUENV_REMOTE=https://artifactory.example.com/artifactory/github TOFUENV_INSTALL_MODE=direct TOFUENV_LIST_MODE=html ``` -------------------------------- ### Install Cosign via DPKG Package (Linux) Source: https://github.com/tofuutils/tenv/blob/main/README.md Installs the cosign tool on Linux distributions that use DPKG packages (like Debian/Ubuntu). This script fetches the latest version and installs it. ```sh LATEST_VERSION=$(curl https://api.github.com/repos/sigstore/cosign/releases/latest | jq -r .tag_name | tr -d "v") curl -O -L "https://github.com/sigstore/cosign/releases/latest/download/cosign_${LATEST_VERSION}_amd64.deb" sudo dpkg -i cosign_${LATEST_VERSION}_amd64.deb ``` -------------------------------- ### List Remote Installable Tool Versions with Tenv Source: https://github.com/tofuutils/tenv/blob/main/README.md Lists all available versions of a tool from the remote URL, sorted in ascending order. Use --descending or -d for descending order and --stable or -s to show only stable versions. ```bash $ tenv tofu list-remote Fetching all releases information from https://api.github.com/repos/opentofu/opentofu/releases 1.6.0-alpha1 1.6.0-alpha2 1.6.0-alpha3 1.6.0-alpha4 1.6.0-alpha5 1.6.0-beta1 1.6.0-beta2 1.6.0-beta3 1.6.0-beta4 1.6.0-beta5 1.6.0-rc1 1.6.0 (installed) 1.6.1 (installed) ``` -------------------------------- ### Install Terraform using min-required strategy Source: https://context7.com/tofuutils/tenv/llms.txt Installs the minimum required Terraform version as specified in project IaC files. ```sh # Install the minimally required version from IaC files tenv tf install min-required ``` -------------------------------- ### Install Specific Tofu and Terraform Versions Source: https://context7.com/tofuutils/tenv/llms.txt Programmatically install one or multiple specific versions of Tofu or Terraform using `tenv.Install` and `tenv.InstallMultiple`. Ensure Tenv is initialized with `tenvlib.Make`. ```go package main import ( "context" "fmt" "github.com/tofuutils/tenv/v4/config/cmdconst" "github.com/tofuutils/tenv/v4/versionmanager/tenvlib" ) func main() { tenv, err := tenvlib.Make(tenvlib.DisableDisplay) if err != nil { fmt.Println("init failed:", err) return } ctx := context.Background() // Install a single version if err = tenv.Install(ctx, cmdconst.TofuName, "1.6.0"); err != nil { fmt.Println("install failed:", err) return } // Install multiple versions in a single locked batch if err = tenv.InstallMultiple(ctx, cmdconst.TerraformName, []string{"1.6.6", "1.7.0", "1.7.2"}); err != nil { fmt.Println("batch install failed:", err) return } fmt.Println("All versions installed successfully") } ``` -------------------------------- ### Install Cosign via MacPorts (MacOS) Source: https://github.com/tofuutils/tenv/blob/main/README.md Installs the cosign tool on macOS using the MacPorts package manager. Ensure MacPorts is installed first. ```sh sudo port install cosign ``` -------------------------------- ### Install Tenv via Nix Package Manager Source: https://github.com/tofuutils/tenv/blob/main/README.md Installs the tenv package using the Nix package manager. This command works across various operating systems where Nix is installed. ```sh nix-env -i tenv ``` -------------------------------- ### Install Terraform including pre-release versions Source: https://context7.com/tofuutils/tenv/llms.txt Installs the latest available Terraform release, including any pre-release versions. ```sh # Include pre-release versions tenv tf install latest-pre ``` -------------------------------- ### Install Tenv via Chocolatey (Windows) Source: https://github.com/tofuutils/tenv/blob/main/README.md Installs the tenv package on Windows using the Chocolatey package manager. ```console choco install tenv ``` -------------------------------- ### Install Tenv via AUR Helper (Arch Linux) Source: https://github.com/tofuutils/tenv/blob/main/README.md Installs the tenv package on Arch Linux using an AUR helper like 'yay'. ```sh yay tenv-bin ``` -------------------------------- ### Install tenv on NixOS via nix-shell Source: https://github.com/tofuutils/tenv/blob/main/README.md Installs tenv temporarily using the nix-shell command on NixOS. ```sh nix-shell -p tenv ``` -------------------------------- ### List all installable remote OpenTofu versions Source: https://context7.com/tofuutils/tenv/llms.txt Fetches and lists all available OpenTofu versions from the remote repository. ```sh tenv tofu list-remote ``` -------------------------------- ### Install tenv via Chocolatey or Scoop Source: https://context7.com/tofuutils/tenv/llms.txt Install tenv on Windows using either Chocolatey or Scoop package managers. ```sh choco install tenv ``` ```sh scoop install tenv ``` -------------------------------- ### Configure Tenv with `WithConfig` and `config.DefaultConfig` Source: https://context7.com/tofuutils/tenv/llms.txt Utilize `tenvlib.WithConfig` to pass a custom configuration object, such as `config.DefaultConfig` or one initialized from environment variables. This allows fine-grained control over Tenv's behavior, including skipping installations and forcing remote lookups. ```go package main import ( "context" "fmt" "github.com/tofuutils/tenv/v4/config" "github.com/tofuutils/tenv/v4/config/cmdconst" "github.com/tofuutils/tenv/v4/versionmanager/semantic" "github.com/tofuutils/tenv/v4/versionmanager/tenvlib" ) func main() { conf, err := config.DefaultConfig() if err != nil { fmt.Println("init failed:", err) return } conf.SkipInstall = false // equivalent to AutoInstall option tenv, err := tenvlib.Make(tenvlib.WithConfig(&conf), tenvlib.DisableDisplay) if err != nil { fmt.Println("init failed:", err) return } ctx := context.Background() // Evaluate resolves "latest" locally localVersion, err := tenv.Evaluate(ctx, cmdconst.TerraformName, semantic.LatestKey) if err != nil { fmt.Println("eval failed:", err) return } // Force remote lookup conf.ForceRemote = true remoteVersion, err := tenv.Evaluate(ctx, cmdconst.TerraformName, semantic.LatestKey) if err != nil { fmt.Println("eval remote failed:", err) return } if localVersion != remoteVersion { // Remove outdated local version _ = tenv.Uninstall(ctx, cmdconst.TerraformName, localVersion) } fmt.Printf("Terraform: %s (local), %s (remote)\n", localVersion, remoteVersion) } ``` -------------------------------- ### Install latest Terragrunt release Source: https://context7.com/tofuutils/tenv/llms.txt Installs the latest stable release of Terragrunt. ```sh # Install latest stable release tenv tg install latest ``` -------------------------------- ### Install Cosign via Arch Linux Package Manager Source: https://github.com/tofuutils/tenv/blob/main/README.md Installs the cosign tool on Arch Linux using the pacman package manager. ```sh sudo pacman -S cosign ``` -------------------------------- ### Install tenv via yum Source: https://github.com/tofuutils/tenv/blob/main/README.md Installs the tenv package using the yum package manager after setting up the Cloudsmith repository. ```sh curl -1sLf 'https://dl.cloudsmith.io/public/tofuutils/tenv/cfg/setup/bash.rpm.sh' | sudo bash sudo yum install tenv ``` -------------------------------- ### Install Tenv via MacPorts (MacOS) Source: https://github.com/tofuutils/tenv/blob/main/README.md Installs the tenv package on macOS using the MacPorts package manager. ```console sudo port install tenv ``` -------------------------------- ### Install Terraform using semver constraint Source: https://context7.com/tofuutils/tenv/llms.txt Installs a Terraform version that satisfies the specified semantic version constraint. ```sh # Install using a semver constraint tenv tf install "~> 1.6.0" ``` -------------------------------- ### List Installed Tool Versions with Tenv Source: https://github.com/tofuutils/tenv/blob/main/README.md Lists all installed versions of a tool, sorted in ascending order by default. Use the -v flag to show the version set by the TENV_ROOT/version file. The --descending or -d flag can be used for descending order. ```bash $ tenv tofu list -v * 1.6.0 (set by /home/dvaumoron/.tenv/OpenTofu/version) 1.6.1 found 2 OpenTofu version(s) managed by tenv. ``` -------------------------------- ### Install Cosign via Alpine Linux Package Manager Source: https://github.com/tofuutils/tenv/blob/main/README.md Installs the cosign tool on Alpine Linux using the apk package manager. ```sh apk add cosign ``` -------------------------------- ### Querying Versions with Tenv.ListLocal, Tenv.ListRemote, and Tenv.LocallyInstalled Source: https://context7.com/tofuutils/tenv/llms.txt This section demonstrates how to query locally installed and remotely available versions of tools using the `ListLocal`, `ListRemote`, and `LocallyInstalled` methods of the Tenv library. ```APIDOC ## Tenv.ListLocal, Tenv.ListRemote, and Tenv.LocallyInstalled Query locally installed and remotely available versions. ### Method Signature `ListLocal(ctx context.Context, toolName string, includePrerelease bool) ([]VersionInfo, error)` `ListRemote(ctx context.Context, toolName string, includePrerelease bool) ([]string, error)` `LocallyInstalled(ctx context.Context, toolName string) (map[string]struct{}, error)` ### Description - `ListLocal`: Retrieves a list of locally installed versions for a given tool, including their last-use date. - `ListRemote`: Retrieves a list of remotely available versions for a given tool. - `LocallyInstalled`: Checks if a specific tool is installed locally and returns a set of installed versions. ### Parameters - `ctx` (context.Context): The context for the operation. - `toolName` (string): The name of the tool to query (e.g., "tofu", "terraform", "terragrunt"). - `includePrerelease` (bool): Whether to include pre-release versions in the results (for `ListLocal` and `ListRemote`). ### Response - `ListLocal`: Returns a slice of `VersionInfo` structs, each containing `Version` (string) and `UseDate` (time.Time). - `ListRemote`: Returns a slice of strings, where each string is a version number. - `LocallyInstalled`: Returns a map where keys are installed version strings and values are empty structs. ``` -------------------------------- ### Install tenv on Alpine Linux Source: https://context7.com/tofuutils/tenv/llms.txt Install tenv on Alpine Linux using the apk package manager, specifying the testing repository. ```sh apk add tenv --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing/ ``` -------------------------------- ### Display Tenv Version Source: https://github.com/tofuutils/tenv/blob/main/README.md This command shows the currently installed version of tenv. It's a simple utility for verifying the tenv installation. ```bash $ tenv version tenv version v1.7.0 ``` -------------------------------- ### List installed Terraform versions in descending order Source: https://context7.com/tofuutils/tenv/llms.txt Lists all locally installed Terraform versions sorted in descending order. ```sh tenv tf list --descending ``` -------------------------------- ### Install Tool Version with tenv Source: https://github.com/tofuutils/tenv/blob/main/README.md Installs a specified or automatically resolved version of a tool. Supports exact versions, version constraints, 'latest', 'latest-pre', and dynamic resolution using 'latest-allowed' or 'min-required' by scanning project files. ```console tenv tofu install tenv tofu install 1.6.0-beta5 tenv tf install "~> 1.6.0" tenv tf install latest-pre tenv tg install latest tenv tg install latest-stable tenv atmos install "~> 1.70" tenv atmos install latest tenv install latest-allowed tenv install min-required ``` ```console $ tenv tofu install 1.6.0 Installing OpenTofu 1.6.0 Fetching release information from https://api.github.com/repos/opentofu/opentofu/releases/tags/v1.6.0 Downloading https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_linux_amd64.zip Downloading https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_SHA256SUMS Downloading https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_SHA256SUMS.sig Downloading https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_SHA256SUMS.pem Installation of OpenTofu 1.6.0 successful ``` -------------------------------- ### Auto-install OpenTofu if not present Source: https://context7.com/tofuutils/tenv/llms.txt Enables automatic installation of OpenTofu when a version is not found, using the TOFUENV_AUTO_INSTALL environment variable. ```sh # Auto-install if not present (via env var) TOFUENV_AUTO_INSTALL=true tenv tofu use 1.6.0 # Written 1.6.0 in /home/user/.tenv/OpenTofu/version ``` -------------------------------- ### Get Help for Tenv Commands Source: https://github.com/tofuutils/tenv/blob/main/README.md Provides help information for any tenv command. The --help or -h flag can be used as an alternative. ```bash $ tenv help tf detect Display Terraform current version. Usage: tenv tf detect [flags] Flags: -a, --arch string specify arch for binaries downloading (default "amd64") -f, --force-remote force search on versions available at TFENV_REMOTE url -h, --help help for detect -k, --key-file string local path to PGP public key file (replace check against remote one) -n, --no-install disable installation of missing version -c, --remote-conf string path to remote configuration file (advanced settings) -u, --remote-url string remote url to install from Global Flags: -q, --quiet no unnecessary output (and no log) -r, --root-path string local path to install versions of OpenTofu, Terraform and Terragrunt (default "/home/dvaumoron/.tenv") -v, --verbose verbose output (and set log level to Trace) ``` ```bash $ tenv tofu use -h Switch the default OpenTofu version to use (set in TENV_ROOT/OpenTofu/version file) Available parameter options: - an exact Semver 2.0.0 version string to use - a version constraint expression (checked against version available in TENV_ROOT directory) - latest, latest-stable or latest-pre (checked against version available in TENV_ROOT directory) - latest-allowed or min-required to scan your OpenTofu files to detect which version is maximally allowed or minimally required. Usage: tenv tofu use version [flags] Flags: -a, --arch string specify arch for binaries downloading (default "amd64") -f, --force-remote force search on versions available at TOFUENV_REMOTE url -t, --github-token string GitHub token (increases GitHub REST API rate limits) -h, --help help for use -k, --key-file string local path to PGP public key file (replace check against remote one) ``` -------------------------------- ### Display Tenv Version Source: https://context7.com/tofuutils/tenv/llms.txt Shows the currently installed version of the tenv tool. ```sh tenv version # tenv version v1.7.0 ``` -------------------------------- ### Basic tenv library usage Source: https://github.com/tofuutils/tenv/blob/main/TENV_AS_LIB.md Demonstrates initializing the tenv library and executing a command proxy. Ensure the context is properly managed and error handling is in place. ```go package main import ( "context" "fmt" "github.com/tofuutils/tenv/v4/config/cmdconst" "github.com/tofuutils/tenv/v4/versionmanager/tenvlib" ) func main() { tenv, err := tenvlib.Make(tenvlib.AutoInstall, tenvlib.IgnoreEnv, tenvlib.DisableDisplay) if err != nil { fmt.Println("init failed :", err) return } err = tenv.DetectedCommandProxy(context.Background(), cmdconst.TofuName, "version") if err != nil { fmt.Println("proxy call failed :", err) } } ``` -------------------------------- ### Use Specific OpenTofu Version with tenv Source: https://github.com/tofuutils/tenv/blob/main/README.md Use this command to specify an OpenTofu version. If the version is not installed, auto-installation remains disabled by default. ```console $ tenv use 1.6.1 Written 1.6.1 in /home/dvaumoron/.tenv/OpenTofu/version ``` -------------------------------- ### Download and verify tenv release artifacts with bash Source: https://github.com/tofuutils/tenv/blob/main/README.md A bash script to automate the download and verification of tenv release files, including checksums, signatures, and RPM packages. This is useful for automated installations in developer environments. ```bash # Get latest release LATEST_VERSION=$(curl --silent https://api.github.com/repos/tofuutils/tenv/releases/latest | jq -r .tag_name) #v2.6.1 # Get checksum files curl --silent -OL https://github.com/tofuutils/tenv/releases/download/${LATEST_VERSION}/tenv_${LATEST_VERSION}_checksums.txt curl --silent -OL https://github.com/tofuutils/tenv/releases/download/${LATEST_VERSION}/tenv_${LATEST_VERSION}_checksums.txt.sig curl --silent -OL https://github.com/tofuutils/tenv/releases/download/${LATEST_VERSION}/tenv_${LATEST_VERSION}_checksums.txt.pem # Get RPM files curl --silent -OL https://github.com/tofuutils/tenv/releases/download/${LATEST_VERSION}/tenv_${LATEST_VERSION}_amd64.rpm curl --silent -OL https://github.com/tofuutils/tenv/releases/download/${LATEST_VERSION}/tenv_${LATEST_VERSION}_amd64.rpm.sig curl --silent -OL https://github.com/tofuutils/tenv/releases/download/${LATEST_VERSION}/tenv_${LATEST_VERSION}_amd64.rpm.pem ``` -------------------------------- ### Set Terraform Remote and List URL Source: https://github.com/tofuutils/tenv/blob/main/README.md Configure Terraform to use a remote mirror for binaries and fetch release listings from the official HashiCorp API. This allows using a mirror for downloads while getting the latest release info from the source. ```console TFENV_REMOTE=https://artifactory.example.com/artifactory/hashicorp TFENV_LIST_URL=https://releases.hashicorp.com ``` -------------------------------- ### Auto-install OpenTofu 1.6.0 Source: https://github.com/tofuutils/tenv/blob/main/README.md Demonstrates enabling auto-installation of a specific OpenTofu version when it's not found. This is useful for CI/CD pipelines or environments where OpenTofu needs to be available on demand. ```bash $ TOFUENV_AUTO_INSTALL=true tenv tofu use 1.6.0 Installing OpenTofu 1.6.0 Fetching release information from https://api.github.com/repos/opentofu/opentofu/releases/tags/v1.6.0 Downloading https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_linux_amd64.zip Downloading https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_SHA256SUMS Downloading https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_SHA256SUMS.sig Downloading https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_SHA256SUMS.pem Installation of OpenTofu 1.6.0 successful Written 1.6.0 in /home/dvaumoron/.tenv/OpenTofu/version ``` -------------------------------- ### Tenv.Detect and Tenv.DetectedCommand Source: https://context7.com/tofuutils/tenv/llms.txt Resolve the version for the working directory and build an `exec.Cmd` without immediately running it. ```APIDOC ## Go Library — `Tenv.Detect` and `Tenv.DetectedCommand` Resolve the version for the working directory and build an `exec.Cmd` without immediately running it. ### Example Usage ```go package main import ( "context" "fmt" "os" "github.com/tofuutils/tenv/v4/config/cmdconst" "github.com/tofuutils/tenv/v4/versionmanager/tenvlib" ) func main() { tenv, err := tenvlib.Make(tenvlib.AutoInstall) if err != nil { fmt.Println("init failed:", err) return } ctx := context.Background() // Detect version without running version, err := tenv.Detect(ctx, cmdconst.TofuName) if err != nil { fmt.Println("detect failed:", err) return } fmt.Println("Detected version:", version) // Build an exec.Cmd to run tofu init cmd, err := tenv.DetectedCommand(ctx, cmdconst.TofuName, "init", "-input=false") if err != nil { fmt.Println("command build failed:", err) return } cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr if err = cmd.Run(); err != nil { fmt.Println("command failed:", err) } } ``` ``` -------------------------------- ### Manage Default Constraints and Versions with Tenv Go Library Source: https://context7.com/tofuutils/tenv/llms.txt Programmatically manage global constraint and version files using `SetDefaultConstraint`, `SetDefaultVersion`, `ResetDefaultConstraint`, and `ResetDefaultVersion`. Ensure the tenv library is initialized. ```go package main import ( "context" "fmt" "github.com/tofuutils/tenv/v4/config/cmdconst" "github.com/tofuutils/tenv/v4/versionmanager/tenvlib" ) func main() { tenv, err := tenvlib.Make(tenvlib.DisableDisplay) if err != nil { fmt.Println("init failed:", err) return } ctx := context.Background() // Set a constraint (writes to $TENV_ROOT/Terraform/constraint) if err = tenv.SetDefaultConstraint(ctx, cmdconst.TerraformName, "<= 1.5.7"); err != nil { fmt.Println("set constraint failed:", err) return } // Set default version globally (workingDir=false → writes $TENV_ROOT/OpenTofu/version) if err = tenv.SetDefaultVersion(ctx, cmdconst.TofuName, "1.6.1", false); err != nil { fmt.Println("set version failed:", err) return } // Set default version in working directory (workingDir=true → writes .opentofu-version) if err = tenv.SetDefaultVersion(ctx, cmdconst.TofuName, "latest", true); err != nil { fmt.Println("set working dir version failed:", err) return } // Reset (remove) the default constraint file if err = tenv.ResetDefaultConstraint(ctx, cmdconst.TerraformName); err != nil { fmt.Println("reset constraint failed:", err) } // Reset the default version file if err = tenv.ResetDefaultVersion(ctx, cmdconst.TofuName); err != nil { fmt.Println("reset version failed:", err) } fmt.Println("Constraint and version files managed successfully") } ``` -------------------------------- ### Create Tenv Instance with Functional Options Source: https://context7.com/tofuutils/tenv/llms.txt Use `tenvlib.Make` with functional options like `AutoInstall`, `IgnoreEnv`, and `DisableDisplay` to configure Tenv behavior. Requires Go 1.23+. ```go package main import ( "context" "fmt" "github.com/tofuutils/tenv/v4/config/cmdconst" "github.com/tofuutils/tenv/v4/versionmanager/tenvlib" ) func main() { // AutoInstall: install missing versions automatically // IgnoreEnv: ignore TENV_* environment variables // DisableDisplay: suppress all output/logging tenv, err := tenvlib.Make( tenvlib.AutoInstall, tenvlib.IgnoreEnv, tenvlib.DisableDisplay, ) if err != nil { fmt.Println("init failed:", err) return } // Detect the correct OpenTofu version and run `tofu version` err = tenv.DetectedCommandProxy(context.Background(), cmdconst.TofuName, "version") if err != nil { fmt.Println("proxy call failed:", err) } // Output: OpenTofu v1.6.1 on linux_amd64 } ``` -------------------------------- ### Detect Version and Build Executable Command Source: https://context7.com/tofuutils/tenv/llms.txt Use `tenv.Detect` to resolve the version for the current working directory without executing any commands. Subsequently, use `tenv.DetectedCommand` to build an `exec.Cmd` for a specific tool and arguments, which can then be run manually. ```go package main import ( "context" "fmt" "os" "github.com/tofuutils/tenv/v4/config/cmdconst" "github.com/tofuutils/tenv/v4/versionmanager/tenvlib" ) func main() { tenv, err := tenvlib.Make(tenvlib.AutoInstall) if err != nil { fmt.Println("init failed:", err) return } ctx := context.Background() // Detect version without running version, err := tenv.Detect(ctx, cmdconst.TofuName) if err != nil { fmt.Println("detect failed:", err) return } fmt.Println("Detected version:", version) // Build an exec.Cmd to run tofu init cmd, err := tenv.DetectedCommand(ctx, cmdconst.TofuName, "init", "-input=false") if err != nil { fmt.Println("command build failed:", err) return } cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr if err = cmd.Run(); err != nil { fmt.Println("command failed:", err) } } ``` -------------------------------- ### tenvlib.Make Source: https://context7.com/tofuutils/tenv/llms.txt Creates a Tenv instance for programmatic use. Accepts functional options to control behavior. Requires Go 1.23+. ```APIDOC ## Go Library — `tenvlib.Make` Creates a `Tenv` instance for programmatic use. Accepts functional options to control behavior. Requires Go 1.23+. ### Options - `tenvlib.AutoInstall`: install missing versions automatically - `tenvlib.IgnoreEnv`: ignore TENV_* environment variables - `tenvlib.DisableDisplay`: suppress all output/logging ### Example Usage ```go package main import ( "context" "fmt" "github.com/tofuutils/tenv/v4/config/cmdconst" "github.com/tofuutils/tenv/v4/versionmanager/tenvlib" ) func main() { tenv, err := tenvlib.Make( tenvlib.AutoInstall, tenvlib.IgnoreEnv, tenvlib.DisableDisplay, ) if err != nil { fmt.Println("init failed:", err) return } err = tenv.DetectedCommandProxy(context.Background(), cmdconst.TofuName, "version") if err != nil { fmt.Println("proxy call failed:", err) } } ``` ``` -------------------------------- ### tenvlib.Make with WithConfig Source: https://context7.com/tofuutils/tenv/llms.txt Use `config.DefaultConfig` or `config.InitConfigFromEnv` for fine-grained control over Tenv configuration. ```APIDOC ## Go Library — `tenvlib.Make` with `WithConfig` Use `config.DefaultConfig` (ignores env vars) or `config.InitConfigFromEnv` (reads env vars) for fine-grained control. ### Example Usage ```go package main import ( "context" "fmt" "github.com/tofuutils/tenv/v4/config" "github.com/tofuutils/tenv/v4/config/cmdconst" "github.com/tofuutils/tenv/v4/versionmanager/semantic" "github.com/tofuutils/tenv/v4/versionmanager/tenvlib" ) func main() { conf, err := config.DefaultConfig() if err != nil { fmt.Println("init failed:", err) return } conf.SkipInstall = false // equivalent to AutoInstall option tenv, err := tenvlib.Make(tenvlib.WithConfig(&conf), tenvlib.DisableDisplay) if err != nil { fmt.Println("init failed:", err) return } ctx := context.Background() localVersion, err := tenv.Evaluate(ctx, cmdconst.TerraformName, semantic.LatestKey) if err != nil { fmt.Println("eval failed:", err) return } conf.ForceRemote = true remoteVersion, err := tenv.Evaluate(ctx, cmdconst.TerraformName, semantic.LatestKey) if err != nil { fmt.Println("eval remote failed:", err) return } if localVersion != remoteVersion { _ = tenv.Uninstall(ctx, cmdconst.TerraformName, localVersion) } fmt.Printf("Terraform: %s (local), %s (remote)\n", localVersion, remoteVersion) } ``` ``` -------------------------------- ### Manage Lock Files for Concurrent Installs Source: https://context7.com/tofuutils/tenv/llms.txt tenv uses lock files to prevent race conditions during concurrent installations. If a lock file exists, subsequent instances will retry until the lock is released. ```sh # Concurrent installs — second instance retries until lock is released tenv tofu install 1.6.0 & tenv tofu install 1.6.1 # [1] Installing OpenTofu 1.6.0 # [2] can not write .lock file, will retry: file already exists # [1] Installation of OpenTofu 1.6.0 successful # [2] Installing OpenTofu 1.6.1 # [2] Installation of OpenTofu 1.6.1 successful ``` ```sh # Custom lock file location export TENV_LOCK_PATH=/tmp/tenv-locks ``` -------------------------------- ### Run tenv help via Docker Source: https://context7.com/tofuutils/tenv/llms.txt Execute the tenv help command within a Docker container for quick access to CLI information. ```sh docker run -it --rm tofuutils/tenv:latest help ``` -------------------------------- ### Write local OpenTofu version file Source: https://context7.com/tofuutils/tenv/llms.txt Uses the --working-dir flag to write a local .opentofu-version file in the current directory. ```sh # Write .opentofu-version in the current working directory tenv tofu use latest --working-dir ``` -------------------------------- ### Override Atmos Version Source: https://github.com/tofuutils/tenv/blob/main/README.md Set the ATMOS_VERSION environment variable to override the Atmos version specified in .atmos-version files. This affects the 'install' and 'detect' subcommands. ```bash ATMOS_VERSION=1.70 atmos version ``` -------------------------------- ### Set Terramate Version with TM_VERSION Source: https://github.com/tofuutils/tenv/blob/main/README.md Use the TM_VERSION environment variable to override the Terramate version. This is respected by `tenv tm install` and `detect` subcommands. ```bash terramate version 0.13.0 ``` ```bash TM_VERSION=0.12.0 terramate version 0.12.0 ``` -------------------------------- ### Display Current Atmos Version Source: https://github.com/tofuutils/tenv/blob/main/README.md Shows the currently active Atmos version. This command is useful for verifying the installed version or checking the effect of environment variables like ATMOS_VERSION. ```console $ atmos version 👽 Atmos v1.72.0 on linux/amd64 ``` -------------------------------- ### Uninstall Tool Versions Source: https://context7.com/tofuutils/tenv/llms.txt Removes installed versions of a tool. Accepts specific versions, constraints like 'but-last', or time-based filters like 'not-used-for:' or 'not-used-since:'. ```sh # Remove a specific version immediately (no confirmation) tenv tofu uninstall 1.6.0-alpha4 # Uninstallation of OpenTofu 1.6.0-alpha4 successful (directory /home/user/.tenv/OpenTofu/1.6.0-alpha4 removed) ``` ```sh # Remove all versions except the highest installed tenv tf uninstall but-last ``` ```sh # Remove versions not used in the last 14 days tenv tg uninstall not-used-for:14d ``` ```sh # Remove versions not used since a specific date tenv atmos uninstall not-used-since:2024-06-30 ``` -------------------------------- ### YAML Configuration for Remote Mirroring Source: https://github.com/tofuutils/tenv/blob/main/README.md Define remote mirroring configurations for OpenTofu and Terraform using a YAML file. This centralizes settings for URL, installation mode, and release listing, simplifying management. ```yaml tofu: url: "https://artifactory.example.com/artifactory/github" install_mode: "direct" list_url: "https://api.github.com/repos/opentofu/opentofu/releases" terraform: url: "https://artifactory.example.com/artifactory/hashicorp" list_mode: "html" ```