How to upgrade Terraform Version

Published on March 25, 2023 · Updated on March 24, 2023
How to upgrade Terraform Version

Terraform is a popular infrastructure-as-code tool used to automate the deployment of infrastructure on cloud platforms like AWS, GCP, and Azure. As new versions of Terraform are released, it’s important to keep your installation up-to-date to take advantage of bug fixes, new features, and performance improvements. In this blog post, we will show you how to upgrade Terraform to the latest version on your machine.

Install tfenv and Verify tfenv Installation

tfenv is a popular tool used to manage Terraform versions. It allows you to easily switch between different versions of Terraform, and upgrade or downgrade as needed.

Install tfenv on MacOS

You can install tfenv on MacOS using Homebrew, a popular package manager for MacOS. To install Homebrew, open Terminal and run the following command:

brew install tfenv

Installing tfenv on Linux

Make sure you have git installed on your system. Then clone the github repo and add the .tfenv variable to your bashrc.

git clone https://github.com/tfutils/tfenv.git ~/.tfenv echo ’export PATH="$HOME/.tfenv/bin:$PATH"’ » ~/.bashrc source ~/.bashrc

Installing tfenv on Windows

You can install tfenv on Windows using Scoop, a popular package manager for Windows. To install Scoop, open PowerShell as an administrator and run the following command:

iwr -useb get.scoop.sh | iex

Once Scoop is installed, you can use it to install tfenv by running the following command:

scoop install tfenv

Verify tfenv installation

To verify that tfenv has been installed correctly, open a new Terminal window and run the following command:

tfenv

You should see the tfenv help output, which means that tfenv has been installed successfully.

List Available Terraform Versions Using tfenv

Now that tfenv is installed, you can use it to list the available Terraform versions by running the following command:

tfenv list-remote

This will display a list of available Terraform versions. You can scroll through the list to find the latest version or the version you want to upgrade to.

Upgrade to a Specific Terraform Version Using tfenv

To upgrade to a specific Terraform version, you can use tfenv to install the version you want. For example, to install version 1.0.9, run the following command:

tfenv install 1.0.9

Once the installation is complete, you can verify the installation by running the following command:

terraform version

This should display the installed version of Terraform.

Upgrade to the Latest Terraform Version Using tfenv

To upgrade to the latest version of Terraform, you can use the following command:

tfenv install latest

This will download and install the latest version of Terraform available from the official releases.

Once the installation is complete, you can verify that the latest version has been installed by running the following command:

terraform -v

This will display the version of Terraform currently installed, which should now be the latest version available.

Install and Switch to a Specific Version Using tfenv

If you want to install and switch to a specific version of Terraform, you can use the following command:

tfenv install <version>

Replace with the version of Terraform you want to install. For example, if you want to install Terraform version 1.0.7, you would use the following command:

tvenv install 1.0.7

Once the installation is complete, you can switch to the newly installed version using the following command:

tfenv use 1.0.7

This will switch your system to use the newly installed version of Terraform.

Conclusion

Upgrading to the latest version of Terraform is an important step to ensure that you have access to the latest features, bug fixes, and security updates. With tfenv, upgrading Terraform is a simple process that can be done in just a few steps.

We’ve covered the steps to install and use tfenv, as well as how to upgrade to a specific version of Terraform and how to upgrade to the latest version. With this knowledge, you should be able to keep your Terraform installation up-to-date and running smoothly.

Load Comments