### Install Latest Implicit Pre-release Version Source: https://context7.com/warrensbox/terraform-switcher/llms.txt Install the latest pre-release version (e.g., beta, RC) that matches a given version prefix. Use flags to install or just display the version. ```shell # Latest pre-release on the 0.13.x branch (e.g. 0.13.0-rc1) tfswitch -p 0.13 tfswitch --latest-pre 0.13 ``` ```shell # Only print the result without installing tfswitch -P 0.13 tfswitch --show-latest-pre 0.13 ``` -------------------------------- ### Install Latest Implicit Pre-release Version Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/commandline.md Install the latest implicit version, including pre-release versions like beta, alpha, and rc. ```bash tfswitch -p 0.13 ``` ```bash tfswitch --latest-pre 0.13 ``` -------------------------------- ### Install tfswitch with Homebrew Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/Installation.md Use this command to install tfswitch on macOS or Linux systems with Homebrew. ```shell brew install warrensbox/tap/tfswitch ``` -------------------------------- ### CircleCI Integration with tfswitch Source: https://context7.com/warrensbox/terraform-switcher/llms.txt Configure tfswitch within a CircleCI pipeline. This example installs tfswitch, sets up a custom binary path, and then uses tfswitch to install a specific Terraform version, ensuring the correct version is available for subsequent commands. ```yaml version: 2 jobs: build: docker: - image: ubuntu steps: - checkout - run: command: | apt-get update && apt-get install -y wget wget https://raw.githubusercontent.com/warrensbox/terraform-switcher/master/install.sh chmod 755 install.sh ./install.sh -b $(pwd)/.bin export PATH=$PATH:$(pwd)/.bin tfswitch -d 1.7.0 -b $(pwd)/.bin/terraform terraform -v ``` -------------------------------- ### Install Terraform to Custom Path Source: https://context7.com/warrensbox/terraform-switcher/llms.txt Installs the Terraform binary to a specified custom directory and sets up a symlink to a specific binary path. ```sh # Install Terraform binary to a custom shared directory # The binary is placed at /opt/terraform/.terraform.versions/ tfswitch -i /opt/terraform ``` ```sh # Point the symlink at a specific binary name/path tfswitch -b "$HOME/bin/terraform" 1.7.0 ``` -------------------------------- ### Install tfswitch with Custom Directory Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/Troubleshoot.md Use this command to install tfswitch in a user-writable directory when facing permission denied errors. Ensure the directory is added to your PATH. ```bash wget https://raw.githubusercontent.com/warrensbox/terraform-switcher/master/install.sh chmod 755 install.sh ./install.sh -b $HOME/.bin $HOME/.bin/tfswitch export PATH=$PATH:$HOME/.bin ``` ```bash tfswitch -b $HOME/.bin/terraform 0.11.7 ``` ```bash tfswitch -b $HOME/.bin/terraform ``` -------------------------------- ### Install tfswitch on Linux via Script Source: https://context7.com/warrensbox/terraform-switcher/llms.txt Install tfswitch on Linux using a curl script. Supports installation to default or custom paths, and specific tfswitch versions. ```shell # Install to default path /usr/local/bin curl -L https://raw.githubusercontent.com/warrensbox/terraform-switcher/master/install.sh | bash ``` ```shell # Install to a custom path (useful when you lack root) curl -L https://raw.githubusercontent.com/warrensbox/terraform-switcher/master/install.sh | bash -s -- -b $HOME/.local/bin ``` ```shell # Install a specific version of tfswitch itself curl -L https://raw.githubusercontent.com/warrensbox/terraform-switcher/master/install.sh | bash -s -- 1.1.1 ``` ```shell # Combine custom path + specific version curl -L https://raw.githubusercontent.com/warrensbox/terraform-switcher/master/install.sh | bash -s -- -b $HOME/.local/bin 1.1.1 ``` -------------------------------- ### Install Binary for Custom CPU Architecture Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/commandline.md Download and install a Terraform binary for a CPU architecture that differs from the host machine's architecture. Downloaded files are stored without architecture in the filename. ```bash tfswitch --arch amd64 ``` -------------------------------- ### Jenkins CI/CD Integration with tfswitch Source: https://context7.com/warrensbox/terraform-switcher/llms.txt Integrate tfswitch into Jenkins pipelines to automatically install and use the correct Terraform version. This example shows how to download tfswitch, set up a custom binary path, and then use tfswitch to manage Terraform versions. ```bash #!/bin/bash wget https://raw.githubusercontent.com/warrensbox/terraform-switcher/master/install.sh chmod 755 install.sh ./install.sh -b $(pwd)/.bin CUSTOMBIN=$(pwd)/.bin export PATH=$PATH:$CUSTOMBIN # Install version specified in version.tf automatically $CUSTOMBIN/tfswitch -b $CUSTOMBIN/terraform # Or pin an explicit version with a fallback default $CUSTOMBIN/tfswitch -d 1.7.0 -b $CUSTOMBIN/terraform terraform -v ``` -------------------------------- ### Install tfswitch on Linux to custom path Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/Installation.md Installs tfswitch on Linux to a specified custom path using a shell script. ```shell curl -L https://raw.githubusercontent.com/warrensbox/terraform-switcher/master/install.sh | bash -s -- -b $HOME/.local/bin ``` -------------------------------- ### Install tfswitch in CircleCI Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/Continuous-Integration.md This YAML configuration for CircleCI sets up a build job that installs tfswitch and a specific Terraform version. It updates apt-get, installs wget, downloads and installs tfswitch, sets the custom bin path, and then uses tfswitch to install Terraform. The Terraform version is verified at the end. ```yaml version: 2 jobs: build: docker: - image: ubuntu working_directory: /go/src/github.com/warrensbox/terraform-switcher steps: - checkout - run: command: | set +e apt-get update apt-get install -y wget rm -rf /var/lib/apt/lists/* echo "Installing tfswitch locally" wget https://raw.githubusercontent.com/warrensbox/terraform-switcher/master/install.sh #Get the installer on to your machine chmod 755 install.sh #Make installer executable ./install.sh -b `pwd`/.bin #Install tfswitch in a location you have permission CUSTOMBIN=`pwd`/.bin #set custom bin path export PATH=$PATH:$CUSTOMBIN #Add custom bin path to PATH environment $CUSTOMBIN/tfswitch -b $CUSTOMBIN/terraform 0.11.7 #or simply tfswitch -b $CUSTOMBIN/terraform 0.11.7 #OR $CUSTOMBIN/tfswitch -d 0.11.7 -b $CUSTOMBIN/terraform #or simply tfswitch -d 0.11.7 -b $CUSTOMBIN/terraform terraform -v #testing version ``` -------------------------------- ### Specify Go Version Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/How-to-Contribute.md Ensure you have the required Go version installed for development. ```sh go version 1.23 ``` -------------------------------- ### Set Product Name with .tfswitch.toml Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/config-files.md Specify the default product (Terraform or OpenTofu) to install by setting the `product` key in `.tfswitch.toml`. ```toml product = "opentofu" ``` ```toml product = "terraform" ``` -------------------------------- ### Install tfswitch in Jenkins Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/Continuous-Integration.md This bash script installs tfswitch locally within a Jenkins job. It downloads the installer, makes it executable, installs tfswitch to a custom bin directory, and adds it to the PATH. Finally, it installs a specific Terraform version using tfswitch and verifies the installation. ```bash #!/bin/bash echo "Installing tfswitch locally" wget https://raw.githubusercontent.com/warrensbox/terraform-switcher/master/install.sh #Get the installer on to your machine chmod 755 install.sh #Make installer executable ./install.sh -b `pwd`/.bin #Install tfswitch in a location you have permission CUSTOMBIN=`pwd`/.bin #set custom bin path export PATH=$PATH:$CUSTOMBIN #Add custom bin path to PATH environment $CUSTOMBIN/tfswitch -b $CUSTOMBIN/terraform 0.11.7 #or simply tfswitch -b $CUSTOMBIN/terraform 0.11.7 #OR $CUSTOMBIN/tfswitch -d 0.11.7 -b $CUSTOMBIN/terraform #or simply tfswitch -d 0.11.7 -b $CUSTOMBIN/terraform terraform -v #testing version ``` -------------------------------- ### Install tfswitch on Linux with custom path and specific version Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/Installation.md Installs a specific version of tfswitch to a custom path on Linux using a shell script. ```shell curl -L https://raw.githubusercontent.com/warrensbox/terraform-switcher/master/install.sh | bash -s -- -b $HOME/.local/bin 1.1.1 ``` -------------------------------- ### Install Latest Stable Terraform Version Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/commandline.md Install only the latest stable version of Terraform. ```bash tfswitch -u ``` ```bash tfswitch --latest ``` -------------------------------- ### Use Custom Mirror for Terraform Installation Source: https://context7.com/warrensbox/terraform-switcher/llms.txt Installs Terraform from a private artifact registry or proxy mirror instead of the default HashiCorp releases. ```sh # Install from a Artifactory proxy mirror tfswitch --mirror https://example.jfrog.io/artifactory/hashicorp ``` ```sh # Use custom mirror with a specific version tfswitch --mirror https://example.jfrog.io/artifactory/hashicorp 1.7.0 ``` -------------------------------- ### Install Latest Stable Terraform Version Source: https://context7.com/warrensbox/terraform-switcher/llms.txt Install the latest stable Terraform version. Use flags to either install directly or just display the version number. ```shell # Install latest stable Terraform tfswitch -u tfswitch --latest ``` ```shell # Only print the latest stable version without installing tfswitch -U tfswitch --show-latest ``` -------------------------------- ### Install specific tfswitch version on Linux Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/Installation.md Installs a specific version of tfswitch on Linux using a shell script. ```shell curl -L https://raw.githubusercontent.com/warrensbox/terraform-switcher/master/install.sh | bash -s -- 1.1.1 ``` -------------------------------- ### Set TF_BINARY_PATH Environment Variable Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/environment-variables.md Specify the full installation path, including the filename, for the binary using TF_BINARY_PATH. If the directory doesn't exist, tfswitch falls back to $HOME/bin/. ```bash export TF_BINARY_PATH="$HOME/bin/terraform" # Path to the file tfswitch # Will install binary as $HOME/bin/terraform ``` -------------------------------- ### Install Latest Implicit Stable Version Source: https://context7.com/warrensbox/terraform-switcher/llms.txt Install the highest published stable release that satisfies a partial version prefix, acting as a Tilde-O-Tilde (~) constraint. Useful for staying within a minor version branch. ```shell # Latest stable on the 0.13.x branch (~> 0.13) tfswitch -s 0.13 tfswitch --latest-stable 0.13 ``` ```shell # Latest stable on the 0.13.5.x branch (~> 0.13.5) tfswitch -s 0.13.5 tfswitch --latest-stable 0.13.5 ``` ```shell # Latest stable on the 0.x branch (~> 0) tfswitch -s 0 tfswitch --latest-stable 0 ``` ```shell # Only print the result without installing tfswitch -S 0.13 tfswitch --show-latest-stable 0.13 ``` -------------------------------- ### Set TF_PRODUCT Environment Variable Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/environment-variables.md Use TF_PRODUCT to specify whether to install 'terraform' or 'opentofu'. ```bash export TF_PRODUCT="opentofu" tfswitch # Will install opentofu instead of terraform ``` -------------------------------- ### Install tfswitch from AUR Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/Installation.md Installs tfswitch on Arch Linux using the Arch User Repository (AUR) with either source compilation or precompiled binaries. ```shell # compiled from source yay tfswitch # precompiled yay tfswitch-bin ``` -------------------------------- ### Specify Custom Binary Path with .tfswitch.toml Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/config-files.md Configure a custom installation path for the Terraform binary by setting the `bin` key in the `.tfswitch.toml` file. This is useful for users without administrative privileges. ```toml bin = "C:\\Users\\<%USERNAME%>\\bin\\terraform.exe" ``` -------------------------------- ### Install Latest Implicit Stable Version Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/commandline.md Install the latest implicit stable version based on a provided version prefix. This command downloads the latest version within a specified branch (e.g., latest on '0.*' branch for '0.13'). ```bash tfswitch -s 0.13 ``` ```bash tfswitch --latest-stable 0.13 ``` ```bash tfswitch -s 0.13.5 ``` ```bash tfswitch --latest-stable 0.13.5 ``` ```bash tfswitch -s 0 ``` ```bash tfswitch --latest-stable 0 ``` -------------------------------- ### Install Terraform to Non-Default Location Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/commandline.md Install Terraform binaries to a custom directory path outside the default user home directory. This is useful for shared installations. The specified directory must exist prior to running the command. ```bash tfswitch -i /opt/terraform ``` -------------------------------- ### Override Installation Directory in .tfswitch.toml Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/config-files.md Configure the `install` parameter in `.tfswitch.toml` to specify a custom parent directory for the Terraform binaries. The current user must have write permissions to the target directory, and tfswitch will create it if it doesn't exist. ```toml install = "/var/cache" ``` -------------------------------- ### Install OpenTofu Instead of Terraform Source: https://context7.com/warrensbox/terraform-switcher/llms.txt Configures tfswitch to install and manage OpenTofu instead of Terraform, using command-line flags, environment variables, or TOML configuration. ```sh # Via command-line flag tfswitch --product opentofu tfswitch -t opentofu ``` ```sh # Via environment variable export TF_PRODUCT="opentofu" tfswitch # installs OpenTofu ``` ```toml # Via .tfswitch.toml # ~/.tfswitch.toml # product = "opentofu" ``` -------------------------------- ### Install Terraform for Specific Architecture Source: https://context7.com/warrensbox/terraform-switcher/llms.txt Downloads a Terraform binary for an architecture different from the host system, useful for cross-platform workflows. ```sh # Download amd64 binary even on an arm64 host tfswitch --arch amd64 ``` ```sh # Download arm64 binary tfswitch -A arm64 1.9.0 ``` -------------------------------- ### Get Project Dependencies Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/How-to-Contribute.md Fetch all project dependencies, including development dependencies, and show verbose output. ```sh go get -v -t -d ./... ``` -------------------------------- ### Install a specific Terraform version Source: https://github.com/warrensbox/terraform-switcher/blob/master/README.md Use this command to install a specific version of Terraform. Replace '1.7.0' with the desired version number. ```shell tfswitch 1.7.0 ``` -------------------------------- ### Show Required Version Source: https://context7.com/warrensbox/terraform-switcher/llms.txt Display the Terraform version that `tfswitch` would install based on all active configuration sources, without performing any installation. Useful for scripting. ```shell # Show the resolved required version tfswitch -R tfswitch --show-required ``` -------------------------------- ### Upgrade tfswitch on Linux Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/Upgrade-or-Uninstall.md Rerun the installation script to upgrade tfswitch on Linux systems. ```shell curl -L https://raw.githubusercontent.com/warrensbox/terraform-switcher/master/install.sh | bash ``` -------------------------------- ### Upgrade tfswitch with Homebrew Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/Upgrade-or-Uninstall.md Use this command to upgrade tfswitch if it was installed via Homebrew. ```shell brew upgrade warrensbox/tap/tfswitch ``` -------------------------------- ### Commit and Push Changes Source: https://github.com/warrensbox/terraform-switcher/blob/master/CHANGELOG.howto.md After updating the CHANGELOG.md, commit the changes using a conventional commit message and push them to your repository. This example uses a 'docs' type commit. ```bash docs: Update CHANGELOG with `` ``` -------------------------------- ### Show Latest Terraform Version Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/commandline.md Display only the latest available Terraform version without installing it. ```bash tfswitch -U ``` ```bash tfswitch --show-latest ``` -------------------------------- ### Uninstall tfswitch with Homebrew Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/Upgrade-or-Uninstall.md Use this command to uninstall tfswitch if it was installed via Homebrew. ```shell brew uninstall warrensbox/tap/tfswitch ``` -------------------------------- ### GitHub Actions Integration with tfswitch Source: https://context7.com/warrensbox/terraform-switcher/llms.txt Set up tfswitch in GitHub Actions to automatically switch to the required Terraform version. This snippet demonstrates installing tfswitch and then running it to detect the version from `version.tf`. ```yaml - name: Install tfswitch run: curl -L https://raw.githubusercontent.com/warrensbox/terraform-switcher/master/install.sh | bash - name: Switch to required Terraform version run: tfswitch # reads required_version from version.tf automatically ``` -------------------------------- ### Check Version Requirement Matching Source: https://context7.com/warrensbox/terraform-switcher/llms.txt Verify if the installed Terraform version meets a specific requirement. Returns a non-zero exit code if the version mismatches or is invalid. ```sh tfswitch --chdir=/tmp/test/ --match-version-requirement=1.10.1; echo $? ``` ```sh tfswitch --chdir=/tmp/test/ --match-version-requirement=string; echo $? ``` ```sh tfswitch --match-version-requirement=1.10.5; echo $? ``` -------------------------------- ### Set Default TF Version for CI/CD Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/ci-cd.md Installs a specified Terraform version as a default when no other versions can be detected in the CI/CD environment. ```bash tfswitch -d 1.2.3 ``` ```bash tfswitch --default 1.2.3 ``` -------------------------------- ### Uninstall tfswitch on Linux Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/Upgrade-or-Uninstall.md Remove the tfswitch executable from your system's PATH. Replace `/usr/local/bin` if installed to a custom location. ```shell rm /usr/local/bin/tfswitch ``` -------------------------------- ### Show Required Terraform Version Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/commandline.md Display the Terraform version that is required based on version constraints from various sources (module, command line, config, env var). Defaults to the latest version if no constraints are found. Can be combined with other options to show the required version for installation. ```bash tfswitch -R ``` ```bash tfswitch --show-required ``` -------------------------------- ### Define Terraform Version Constraint in version.tf Source: https://context7.com/warrensbox/terraform-switcher/llms.txt Specifies Terraform version requirements using `required_version` within a `version.tf` file. `tfswitch` will install the best matching stable version. ```hcl # version.tf terraform { required_version = ">= 1.5.0, < 2.0.0" required_providers { aws = { source = "hashicorp/aws" version = "~> 5.0" } } } ``` -------------------------------- ### Generate New Changelog Entries Source: https://github.com/warrensbox/terraform-switcher/blob/master/CHANGELOG.howto.md Use the `gh changelog new` command to generate new changelog entries between two specified versions. Ensure you have GH CLI and gh-changelog installed and configured. ```bash gh changelog new --from-version --next-version ``` -------------------------------- ### Build the Executable Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/How-to-Contribute.md Compile the Go project into an executable file named 'test-tfswitch'. ```sh go build -o test-tfswitch ``` -------------------------------- ### Download Go Module Dependencies Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/How-to-Contribute.md Download all necessary dependencies for the project using Go modules. ```sh go mod download ``` -------------------------------- ### Build tfswitch Binary Source: https://github.com/warrensbox/terraform-switcher/wiki/How-to-contribute Use this command to build the tfswitch binary from the master branch. This command should be run after checking out the master branch. ```bash make tfswitch ``` -------------------------------- ### Test Code with Go Source: https://github.com/warrensbox/terraform-switcher/wiki/How-to-contribute Run this command to execute all tests in the project. Ensure all tests pass before proceeding with further development or pull requests. ```bash go test -v ./... ``` -------------------------------- ### Global tfswitch Configuration with ~/.tfswitch.toml Source: https://context7.com/warrensbox/terraform-switcher/llms.txt Defines global tfswitch settings, including default version, product, custom paths, architecture, and logging/color preferences, in `~/.tfswitch.toml`. ```toml # ~/.tfswitch.toml # Pin or set default version version = "1.9.0" default-version = "1.7.0" # Product: "terraform" (default) or "opentofu" product = "terraform" # Custom binary path (full path including filename) bin = "/home/user/bin/terraform" # Custom install directory (parent of .terraform.versions/) install = "/var/cache" # Override CPU architecture for downloaded binaries arch = "arm64" # Log level: OFF | PANIC | FATAL | ERROR | WARN | INFO | NOTICE | DEBUG | TRACE log-level = "INFO" # Color settings (mutually exclusive) no-color = false force-color = false ``` -------------------------------- ### Show Latest Implicit Pre-release Version Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/commandline.md Show the latest implicit version, including pre-release versions like beta, alpha, and rc. ```bash tfswitch -P 0.13 ``` ```bash tfswitch --show-latest-pre 0.13 ``` -------------------------------- ### Build and Output tfswitch Binary Source: https://github.com/warrensbox/terraform-switcher/wiki/How-to-contribute Build the tfswitch binary with verbose output and specify the output file name. This is typically done after making code edits and before local testing. ```bash go build -v -o tfswitch ``` -------------------------------- ### Match Specific Product Version Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/commandline.md Verify if a specific product version matches a version requirement defined in the configuration. The exit code indicates the match status: 0 for match, 2 for mismatch, 1 for error, and 0 for no requirement found. ```bash tfswitch --chdir=/tmp/test/ --match-version-requirement=1.10.5; echo $? 20:41:00.226 INFO Reading version constraint from Terraform module at "../../../../tmp/test" 20:41:00.227 INFO Matched version: "1.10.5" 20:41:00.227 INFO Version "1.10.5" matches requirement "~> 1.10.5, < 1.12.0" 0 ``` ```bash tfswitch --chdir=/tmp/test/ --match-version-requirement=1.10.1; echo $? 20:41:17.483 INFO Reading version constraint from Terraform module at "../../../../tmp/test" 20:41:17.484 ERROR Version "1.10.1" mismatches requirement "~> 1.10.5, < 1.12.0" 2 ``` ```bash tfswitch --chdir=/tmp/test/ --match-version-requirement=string; echo $? 20:41:39.199 INFO Reading version constraint from Terraform module at "../../../../tmp/test" 20:41:39.199 ERROR Failed to validate version format: "string" 20:41:39.199 ERROR Version does not exist or invalid terraform version format. Format should be #.#.# or #.#.#-@# where # are numbers and @ are word characters. For example, 1.11.7 and 0.11.9-beta1 are valid versions 1 ``` ```bash tfswitch --match-version-requirement=1.10.5; echo $? 20:41:52.372 WARNING No version requirement found to match against (version "1.10.5" is acceptable) 0 ``` -------------------------------- ### Launch Interactive Version Selector Source: https://context7.com/warrensbox/terraform-switcher/llms.txt Run `tfswitch` without arguments to open an interactive dropdown for selecting Terraform versions. Recently used versions are prioritized. ```shell # Launch interactive selector (stable releases only) tfswitch ``` ```shell # Launch interactive selector including beta, RC and alpha releases tfswitch -l tfswitch --list-all ``` -------------------------------- ### Use Custom Mirror for Terraform Releases Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/commandline.md Specify a custom URL for downloading Terraform releases instead of the default HashiCorp releases URL. ```bash tfswitch --mirror https://example.jfrog.io/artifactory/hashicorp ``` -------------------------------- ### List All Terraform Versions Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/commandline.md Display all available Terraform versions, including beta, alpha, and release candidates (rc). ```bash tfswitch -l ``` ```bash tfswitch --list-all ``` -------------------------------- ### Override CPU Architecture in .tfswitch.toml Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/config-files.md Set the `arch` parameter in `.tfswitch.toml` to download binaries for a specific CPU architecture, such as `arm64`. Incorrect values may cause download failures. Suggested values include `amd64`, `arm64`, and `386`. ```toml arch = "arm64" ``` -------------------------------- ### Select Terraform Version via Command Line Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/commandline.md Specify the desired Terraform version directly as an argument to the tfswitch command. ```bash tfswitch 0.10.5 ``` -------------------------------- ### Set TF_INSTALL_PATH Environment Variable Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/environment-variables.md Specify the parent directory for the .terraform.versions directory using TF_INSTALL_PATH. The user must have write permissions, and the directory will be created if it doesn't exist. ```bash export TF_INSTALL_PATH="/var/cache" # Path to the directory where .terraform.versions directory resides tfswitch # Will download actual binary to /var/cache/.terraform.versions/ ``` -------------------------------- ### Set TF_DEFAULT_VERSION Environment Variable Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/environment-variables.md Use TF_DEFAULT_VERSION to set a fallback version for the product if no other version sources are found. ```bash export TF_DEFAULT_VERSION="0.14.4" tfswitch # Will automatically switch to terraform version 0.14.4 ``` -------------------------------- ### Specify Terraform Version Constraint in Terragrunt HCL Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/config-files.md Define the `terraform_version_constraint` in a `terragrunt.hcl` file to automatically switch to a specific Terraform version. This example sets the constraint to use versions greater than or equal to 0.13 and less than 0.14. ```hcl terraform_version_constraint = ">= 0.13, < 0.14" ``` -------------------------------- ### Specify Version with .tfswitchrc Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/config-files.md Create a `.tfswitchrc` file and add the desired Terraform version on a new line to have tfswitch use it. ```bash echo "0.10.5" >> .tfswitchrc ``` -------------------------------- ### Automatic Version Switching with Zsh Hook Source: https://context7.com/warrensbox/terraform-switcher/llms.txt Sets up a Zsh hook to automatically execute `tfswitch` after changing directories if a `.tfswitchrc` file exists. ```sh autoload -U add-zsh-hook load-tfswitch() { local tfswitchrc_path=".tfswitchrc" if [ -f "$tfswitchrc_path" ]; then tfswitch fi } add-zsh-hook chpwd load-tfswitch load-tfswitch ``` -------------------------------- ### Automatically Switch Terraform Version with Fish Shell Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/ci-cd.md Sets up a `fish_postexec` hook to automatically run `tfswitch` after the `cd` command if Terraform version constraints are detected in `.tf` files. ```fish function switch_terraform --on-event fish_postexec string match --regex '^cd\s' "$argv" > /dev/null set --local is_command_cd $status if test $is_command_cd -eq 0 if count *.tf > /dev/null grep -c "required_version" *.tf > /dev/null set --local tf_contains_version $status if test $tf_contains_version -eq 0 command tfswitch end end end end ``` -------------------------------- ### Upgrade and Uninstall tfswitch Source: https://context7.com/warrensbox/terraform-switcher/llms.txt Instructions for upgrading or uninstalling tfswitch using Homebrew on macOS or by re-running the installer/manual removal on Linux. ```bash # Upgrade via Homebrew brew upgrade warrensbox/tap/tfswitch # Upgrade on Linux (re-run installer) curl -L https://raw.githubusercontent.com/warrensbox/terraform-switcher/master/install.sh | bash # Uninstall via Homebrew brew uninstall warrensbox/tap/tfswitch # Uninstall on Linux rm /usr/local/bin/tfswitch ``` -------------------------------- ### Automatically Switch Terraform Version with Bash Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/ci-cd.md Adds a custom `cd` command to `~/.bashrc` that automatically runs `tfswitch` if a `.tfswitchrc` file is present in the new directory. ```bash cdtfswitch(){ builtin cd "$@"; cdir=$PWD; if [ -e "$cdir/.tfswitchrc" ]; then tfswitch fi } alias cd='cdtfswitch' ``` -------------------------------- ### Set TF_ARCH Environment Variable Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/environment-variables.md Use the TF_ARCH environment variable to specify the CPU architecture for downloaded binaries. Incorrect values may cause download failures. ```bash export TF_ARCH="amd64" tfswitch # Will install binary for amd64 architecture ``` -------------------------------- ### Set Log Level with .tfswitch.toml Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/config-files.md Control the logging verbosity by setting the `log-level` parameter in `.tfswitch.toml`. Supported levels range from `OFF` to `TRACE`. ```toml log-level = "INFO" ``` -------------------------------- ### Set Default Version with .tfswitch.toml Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/config-files.md Configure a default Terraform version in `.tfswitch.toml` using the `default-version` key. This version will be used if tfswitch cannot determine the version from other sources. ```toml default-version = "1.5.4" ``` -------------------------------- ### Environment Variables for tfswitch Configuration Source: https://context7.com/warrensbox/terraform-switcher/llms.txt Overrides TOML file settings using environment variables for product selection, version pinning, and default versions. ```sh # Select product export TF_PRODUCT="opentofu" # or "terraform" # Pin version export TF_VERSION="1.9.0" # Fallback/default version when no other source specifies one export TF_DEFAULT_VERSION="1.7.0" ``` -------------------------------- ### Automatically Switch Terraform Version with Zsh Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/ci-cd.md Configures Zsh to automatically run `tfswitch` when changing directories if a `.tfswitchrc` file exists. Includes instructions for older Zsh versions. ```zsh load-tfswitch() { local tfswitchrc_path=".tfswitchrc" if [ -f "$tfswitchrc_path" ]; then tfswitch fi } add-zsh-hook chpwd load-tfswitch load-tfswitch ``` ```zsh autoload -U add-zsh-hook ``` ```zsh cd(){ builtin cd "$@"; cdir=$PWD; if [ -e "$cdir/.tfswitchrc" ]; then tfswitch fi } ``` -------------------------------- ### Clone the Repository Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/How-to-Contribute.md Clone the terraform-switcher repository to your local machine using SSH. ```sh git clone git@github.com:warrensbox/terraform-switcher.git ``` -------------------------------- ### Define Terraform Version in version.tf Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/config-files.md Place a `version.tf` file in the current directory to automatically set the Terraform version. This file should contain the `terraform` block with `required_version`. ```hcl terraform { required_version = ">= 0.12.9" required_providers { aws = ">= 2.52.0" kubernetes = ">= 1.11.1" } } ``` -------------------------------- ### Dry-run Mode Source: https://context7.com/warrensbox/terraform-switcher/llms.txt Simulate `tfswitch` operations without making any changes to the filesystem. This mode is useful for verifying intended actions before execution. ```shell tfswitch --dry-run 1.9.0 # Output: # [DRY-RUN] No changes will be made # [DRY-RUN] Would have attempted to install Terraform version "1.9.0" for "linux_amd64" ``` -------------------------------- ### Show Latest Implicit Stable Version Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/commandline.md Show the latest implicit stable version based on a provided version prefix. This command displays the latest version within a specified branch (e.g., latest on '0.*' branch for '0.13'). ```bash tfswitch -S 0.13 ``` ```bash tfswitch --show-latest-stable 0.13 ``` ```bash tfswitch -S 0.13.5 ``` ```bash tfswitch --show-latest-stable 0.13.5 ``` -------------------------------- ### Change Working Directory with tfswitch Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/config-files.md Use the `--chdir` or `-c` parameter to specify a subdirectory when running tfswitch. ```bash tfswitch --chdir terraform_dir ``` ```bash tfswitch -c terraform_dir ``` -------------------------------- ### Pin Terraform Version with .tfswitchrc Source: https://context7.com/warrensbox/terraform-switcher/llms.txt Pins a single exact Terraform version for a project by creating a `.tfswitchrc` file. This is compatible with `tfenv`. ```hcl # .tfswitchrc 1.7.0 ``` -------------------------------- ### Force Color Output Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/commandline.md Use the --force-color or -K flag to force color output, even in non-interactive sessions. ```bash tfswitch --force-color ``` ```bash tfswitch -K ``` -------------------------------- ### Switch Working Directory for Terraform Configuration Source: https://context7.com/warrensbox/terraform-switcher/llms.txt Specifies a subdirectory from which tfswitch should read version configuration files like .tfswitchrc or version.tf. ```sh # Read version.tf / .tfswitchrc from ./terraform_dir tfswitch --chdir terraform_dir tfswitch -c terraform_dir ``` -------------------------------- ### Automatic Version Switching with Fish Shell Event Source: https://context7.com/warrensbox/terraform-switcher/llms.txt Configures the Fish shell to trigger `tfswitch` after executing the `cd` command if a Terraform version file is found in the new directory. ```fish function switch_terraform --on-event fish_postexec string match --regex '^cd\s' "$argv" > /dev/null set --local is_command_cd $status if test $is_command_cd -eq 0 if count *.tf > /dev/null grep -c "required_version" *.tf > /dev/null set --local tf_contains_version $status if test $tf_contains_version -eq 0 command tfswitch end end end end ``` -------------------------------- ### Set GOPATH Environment Variable Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/How-to-Contribute.md Export the GOPATH environment variable to point to your GitHub Go workspace directory. ```sh export GOPATH=`pwd` ``` -------------------------------- ### Static Analysis of Code Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/How-to-Contribute.md Perform static analysis on the codebase to detect potential issues, excluding tests. ```sh go vet -tests=false ./... ``` -------------------------------- ### Disable or Force Color Output Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/config-files.md Use the `no-color` parameter to disable color output, useful for non-interactive sessions or when piping output. Use `force-color` to enable color output even in non-interactive sessions. These parameters are mutually exclusive. ```toml no-color = true ``` ```toml force-color = true ``` -------------------------------- ### Configure gh-changelog Source: https://github.com/warrensbox/terraform-switcher/blob/master/CHANGELOG.howto.md This YAML configuration file defines how gh-changelog should generate the changelog. Customize excluded labels, section mappings, and output settings. ```yaml --- file_name: CHANGELOG.md.new excluded_labels: - maintenance - dependencies sections: added: - feature - new feature changed: - backwards-incompatible - depricated fixed: - bug - bugfix - enhancement - fix - fixed skip_entries_without_label: false show_unreleased: true check_for_updates: true logger: console ``` -------------------------------- ### Create a New Feature Branch Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/How-to-Contribute.md Create a new Git branch for developing a new feature or fix. Replace 'put-your-branch-name-here' with a descriptive name. ```sh git checkout -b feature/put-your-branch-name-here ``` -------------------------------- ### Match Version Against Requirement Source: https://context7.com/warrensbox/terraform-switcher/llms.txt Check if a specific Terraform version satisfies the version requirement defined in the project's configuration. Returns an exit code indicating match, mismatch, or error. ```shell # Version matches requirement detected from /tmp/test/version.tf (~> 1.10.5, < 1.12.0) tfswitch --chdir=/tmp/test/ --match-version-requirement=1.10.5; echo $? # 20:41:00.227 INFO Version "1.10.5" matches requirement "~> 1.10.5, < 1.12.0" # 0 ``` -------------------------------- ### Set Environment Variables for tfswitch Source: https://context7.com/warrensbox/terraform-switcher/llms.txt Configure tfswitch behavior by setting environment variables. These variables control the binary path, cache directory, CPU architecture, Terragrunt config filename, log level, and color output. ```bash export TF_BINARY_PATH="$HOME/bin/terraform" export TF_INSTALL_PATH="/var/cache" export TF_ARCH="amd64" export TF_TERRAGRUNT_CONFIG_FILE_NAME="tgconfig.hcl" export TF_LOG_LEVEL="DEBUG" export NO_COLOR="1" # disable colors export FORCE_COLOR="1" # force colors in non-TTY tfswitch # picks up all of the above ``` -------------------------------- ### Set Desired Terraform Version Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/environment-variables.md Set the TF_VERSION environment variable to automatically switch to a specific Terraform version. This is useful for ensuring consistent builds or testing specific versions. ```bash export TF_VERSION="0.14.4" tfswitch # Will automatically switch to terraform version 0.14.4 ``` -------------------------------- ### Set TF_LOG_LEVEL Environment Variable Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/environment-variables.md Override the default log level with TF_LOG_LEVEL. Supported levels range from TRACE to OFF. ```bash export TF_LOG_LEVEL="DEBUG" tfswitch # Will output debug logs ``` -------------------------------- ### Disable Color Output Source: https://github.com/warrensbox/terraform-switcher/blob/master/www/docs/usage/commandline.md Use the --no-color or -k flag to disable color output, useful for non-interactive sessions or when piping output. ```bash tfswitch --no-color ``` ```bash tfswitch -k ```