Spacelift + ServiceNow = Self-Service IaC Without the Learning Curve

➡️ Register Now

Terraform

How to Use tfenv to Manage Multiple Terraform Versions

Using tfenv to Manage Multiple Terraform Versions

🚀 Level Up Your Infrastructure Skills

You focus on building. We’ll keep you updated. Get curated infrastructure insights that help you make smarter decisions.

In this article, we will explore the popular Terraform version manager tfenv, with practical examples of how to install it, and use it to add, change and uninstall different Terraform versions. Tfenv enables you to install multiple Terraform versions and switch between them easily as needed.

What is tfenv?

Tfenv is a version manager inspired by rbenv, a Ruby programming language version manager.

Different versions of Terraform might be required when working on multiple projects for different customers at the same time where a particular version is used or to ensure backward compatibility by running the code with multiple versions. Terraform version upgrades can introduce unwanted problems.

One tip to avoid this is to set the required_version in the Terraform block. When this is set, attempting to run the code with a different version will produce an explicit error, and the code will not run. Once you have tested using a different version, the required_version can be updated, effectively ensuring everyone running the code will see the same results.

terraform {
    required_version = "0.12.10"
}

Learn more about how to manage different Terraform versions.

Note: New versions of Terraform are placed under the BUSL license, but everything created before version 1.5.x stays open-source. OpenTofu is an open-source version of Terraform that expands on Terraform’s existing concepts and offerings. It is a viable alternative to HashiCorp’s Terraform, being forked from Terraform version 1.5.6.

Installing tfenv

  1. Clone the repo to your home directory:
git clone --depth=1 https://github.com/tfutils/tfenv.git ~/.tfenv
  1. Add ~/.tfenv/bin to your $PATH:
echo 'export PATH=$PATH:$HOME/.tfenv/bin' >> ~/.bashrc
  1. Add a symlink to the tfenv executable:
sudo ln -s ~/.tfenv/bin/* /usr/local/bin
  1. The unzip package will also need to be installed on your system:
apt-get install unzip
  1. Run tfenv to view the available options— tfenv
tfenv

Install Terraform Versions

tfenv install <version>

tfenv install 1.3.9
tfenv install

Set the version to your default:

tfenv use 1.3.9
tfenv use
list remote

Check your current version in Terraform and in tfenv:

terraform --version
terraform --version
tfenv --version-name
tfenv --version-name

You can also install the latest available version conveniently using:

tfenv install latest
  • latest-allowed is a syntax to scan your Terraform files to detect which version is maximally allowed.
  • min-required is a syntax to scan your Terraform files to detect which version is minimally required.

Change Terraform Versions

To switch and change between your installed Terraform versions, you can first view a list of them:

tfenv list 
tfenv list
tfenv use 1.2.9
tfenv use 1.2.9
tfenv use latest

Uninstall Terraform Versions

To cleanup versions you no longer need on your system, use the uninstall command:

tfenv uninstall 1.2.9

Managing Terraform Resources with Spacelift

Terraform is really powerful, but to achieve an end-to-end secure Gitops approach, you need to use a product that can run your Terraform workflows. Spacelift takes managing Terraform to the next level by giving you access to a powerful CI/CD workflow and unlocking features such as:

  • Policies (based on Open Policy Agent) – You can control how many approvals you need for runs, what kind of resources you can create, and what kind of parameters these resources can have, and you can also control the behavior when a pull request is open or merged.
  • Multi-IaC workflows – Combine Terraform with Kubernetes, Ansible, and other infrastructure-as-code (IaC) tools such as OpenTofu, Pulumi, and CloudFormation,  create dependencies among them, and share outputs
  • Build self-service infrastructure – You can use Blueprints to build self-service infrastructure; simply complete a form to provision infrastructure based on Terraform and other supported tools.
  • Integrations with any third-party tools – You can integrate with your favorite third-party tools and even build policies for them. For example, see how to integrate security tools in your workflows using Custom Inputs.
affinity logo white

Previously, the Affinity team used Terraform both as their runner and for state management. Now, they use Amazon S3 for state management, but because this is connected to the Spacelift provider, state management is something they don’t have to worry about.

Spacelift customer case study

Read the full story

Spacelift enables you to create private workers inside your infrastructure, which helps you execute Spacelift-related workflows on your end. Read the documentation for more information on configuring private workers.

You can check it out for free by creating a trial account or booking a demo with one of our engineers.

Key Points

Achieve Terraform at scale with Spacelift

Spacelift takes managing infrastructure at scale to a whole new level, offering a more open, more customizable, and more extensible product. It’s a better, more flexible CI/CD for Terraform, offering maximum security without sacrificing functionality.

Learn more

The Infrastructure Automation

Report 2025

Our research shows that teams are overconfident

and race toward faster deployments,

sacrificing governance and falling into

the Speed-Control Paradox.

Get the Report