How Do You Play Around with Terraform CLI Versions?
Introduce Reflecting on how I wasn’t able to manage my blog well in 2024 due to a lot going on, today I’d like to introduce an easy tool for managing Terraform CLI versions. If you have any questions, feel free to leave them in the comments, and I will do my best to answer them to the best of my ability. I started with Terraform from version v0.11. Terraform has rapidly evolved to version v1.12.0-alpha, but in real-world environments, we usually stick to a specific version, so we’ve been using Terraform v1.5.7 or earlier. However, recently, while I was preparing to teach, I started using Terraform v1.9.0+ and was looking for a way to make local settings easier. That’s when I came across an open-source tool called tfenv. https://github.com/tfutils/tfenv tfenv is an open-source tool created for managing Terraform CLI versions in the same way as rbenv. When using multiple versions, similar to how Java versions are managed with sudo alternatives --config java, Terraform CLI versions can also be easily managed. Let’s take a look at how it works. tfenv Installation There are two main installation methods provided. The Automatic method allows Mac users to easily install using Brew, and it can also be installed using yay or Puppet modules (though yay and Puppet might not be commonly used). The Manual method involves cloning the repository directly and configuring the pre-configured shell file to work from the bin directory. #tfenv clone git clone --depth=1 https://github.com/tfutils/tfenv.git ~/.tfenv # Choice 1 or 2 method "#1 Set the tfenv subdirectory bin directory in the PATH environment variable" echo 'export PATH="$HOME/.tfenv/bin:$PATH"' >> ~/.zprofile #2 symbolic link ln -s ~/.tfenv/bin/* /usr/local/bin By setting it up as described above, Mac users can use the tfenv command without needing to install it via brew. Managing Terraform CLI Versions with tfenv If you’ve completed the installation process above, let’s now manage the Terraform CLI versions using tfenv If you enter tfenv once, you’ll see a command list like the one above. To check the available Terraform CLI versions for local installation, you can run tfenv list-remote, and it will display a list of installable versions as shown in the picture below. After checking the versions here, you can specify a version using the command tfenv install , or you can run a command like tfenv install latest, and the Terraform CLI will be installed according to the specified version. # Install the version specified by TFENV_TERRAFORM_VERSION or .terraform-version # priority : TFENV_TERRAFORM_VERSION > .terraform-version tfenv install # Install Terraform version 1.9.0 tfenv install 1.9.0 # Install the latest Terraform version tfenv install latest # Install the latest version of Terraform 1.8 tfenv install latest:^1.8 # Install the latest allowed or the minimum required Terraform CLI version tfenv install latest-allowed tfenv install min-required Let's install version 1.9.0 on the local environment using the first method. First, you need to specify either TFENV_TERRAFORM_VERSION or terraform-version. As shown in the picture below, we will specify terraform-version. Then, when you run tfenv install, you will see that the Terraform CLI is downloaded according to the terraform-version specified above. To use the installed Terraform v1.9.0, you simply need to run tfenv use 1.9.0 Next, let’s install another version. We will install the latest version and try switching versions. Before doing that, you need to remove the environment variables. If you don’t, even after installing and switching to a new version, the environment variables will take precedence, and the version switch will not be applied correctly. When you install the latest version, Terraform 1.11.2 will be installed. Then, when you switch from the installed version 1.9.0 to 1.11.2, you can easily switch versions using tfenv use, as shown below. There are also environment variables related to DEBUG, so it’s highly recommended to check the official repository for more details! Enjoy the Terraform ride!

Introduce
Reflecting on how I wasn’t able to manage my blog well in 2024 due to a lot going on, today I’d like to introduce an easy tool for managing Terraform CLI versions.
If you have any questions, feel free to leave them in the comments, and I will do my best to answer them to the best of my ability.
I started with Terraform from version v0.11. Terraform has rapidly evolved to version v1.12.0-alpha, but in real-world environments, we usually stick to a specific version, so we’ve been using Terraform v1.5.7 or earlier.
However, recently, while I was preparing to teach, I started using Terraform v1.9.0+ and was looking for a way to make local settings easier.
That’s when I came across an open-source tool called tfenv.
https://github.com/tfutils/tfenv
tfenv is an open-source tool created for managing Terraform CLI versions in the same way as rbenv.
When using multiple versions, similar to how Java versions are managed with sudo alternatives --config java, Terraform CLI versions can also be easily managed.
Let’s take a look at how it works.
tfenv Installation
There are two main installation methods provided.
The Automatic method allows Mac users to easily install using Brew, and it can also be installed using yay or Puppet modules (though yay and Puppet might not be commonly used).
The Manual method involves cloning the repository directly and configuring the pre-configured shell file to work from the bin directory.
#tfenv clone
git clone --depth=1 https://github.com/tfutils/tfenv.git ~/.tfenv
# Choice 1 or 2 method
"#1 Set the tfenv subdirectory bin directory in the PATH environment variable"
echo 'export PATH="$HOME/.tfenv/bin:$PATH"' >> ~/.zprofile
#2 symbolic link
ln -s ~/.tfenv/bin/* /usr/local/bin
By setting it up as described above, Mac users can use the tfenv command without needing to install it via brew.
Managing Terraform CLI Versions with tfenv
If you’ve completed the installation process above, let’s now manage the Terraform CLI versions using tfenv
If you enter tfenv once, you’ll see a command list like the one above.
To check the available Terraform CLI versions for local installation, you can run tfenv list-remote, and it will display a list of installable versions as shown in the picture below.
After checking the versions here, you can specify a version using the command tfenv install , or you can run a command like tfenv install latest, and the Terraform CLI will be installed according to the specified version.
# Install the version specified by TFENV_TERRAFORM_VERSION or .terraform-version
# priority : TFENV_TERRAFORM_VERSION > .terraform-version
tfenv install
# Install Terraform version 1.9.0
tfenv install 1.9.0
# Install the latest Terraform version
tfenv install latest
# Install the latest version of Terraform 1.8
tfenv install latest:^1.8
# Install the latest allowed or the minimum required Terraform CLI version
tfenv install latest-allowed
tfenv install min-required
Let's install version 1.9.0 on the local environment using the first method.
First, you need to specify either TFENV_TERRAFORM_VERSION or terraform-version. As shown in the picture below, we will specify terraform-version.
Then, when you run tfenv install, you will see that the Terraform CLI is downloaded according to the terraform-version specified above.
To use the installed Terraform v1.9.0, you simply need to run tfenv use 1.9.0
Next, let’s install another version. We will install the latest version and try switching versions.
Before doing that, you need to remove the environment variables.
If you don’t, even after installing and switching to a new version, the environment variables will take precedence, and the version switch will not be applied correctly.
When you install the latest version, Terraform 1.11.2 will be installed.
Then, when you switch from the installed version 1.9.0 to 1.11.2, you can easily switch versions using tfenv use, as shown below.
There are also environment variables related to DEBUG, so it’s highly recommended to check the official repository for more details!
Enjoy the Terraform ride!