Just like a versioning tool such as Git or SVN, which allows you to rollback or upgrade if there is a problem with the current version of your code, tfenv lets you upgrade as well as rollback versions of Terraform.
But why do we need multiple versions of Terraform? A typical infrastructure setup always consists of development, testing, staging, and the production environment. As a rule of thumb, the production environment gets the most stable version. On the other hand, development, test, and sometimes staging environments receive newer versions of any software package. The same goes for Terraform.
If, during the testing phase, there is a bug that breaks the existing infrastructure setup, tfenv can help roll back Terraform to the previous stable version. Similarly, you can upgrade to the next stable version so that your Terraform stack is up to date.
In this post, we’ll see how you can install Terraform and upgrade it to a specific release (for example, Terraform 1.11.x, 1.12.x, or 1.14.x) using tfenv. The commands work the same way for older versions such as 0.12–0.15, but we strongly recommend targeting a recent 1.x release for new projects.
TL;DR
Use tfenv to install and switch between Terraform versions. Run terraform init -upgrade separately to upgrade your providers. Always test version changes in a non-production environment first.
Why should you upgrade your Terraform version?
Staying on an outdated Terraform version means missing out on bug fixes, new language features, and cloud provider support. And in some cases, leaving known security vulnerabilities unpatched. Here’s what you actually gain by keeping Terraform up to date:
- Access to new features and HCL improvements. Each major and minor release adds new language capabilities. Terraform 1.5 introduced
importblocks for declarative resource imports. Version 1.6 addedterraform testfor native unit testing. Version 1.7 broughtremovedblocks for cleanly decommissioning resources without losing state history. If you’re on an older version, you’re writing more code to do less. - Updated cloud provider support. Terraform’s provider ecosystem evolves alongside AWS, Azure, GCP, and others. While provider versions are managed independently of the Terraform core binary, newer Terraform releases often unlock richer provider functionality — especially around newer resource types and authentication methods.
- Performance improvements. Terraform 1.x has significantly faster plan and apply times compared to the 0.12–0.15 era, particularly for large state files and configurations with deep dependency graphs. Staying behind on versions means slower CI/CD pipelines.
- Security patches. Like any piece of software, Terraform receives CVE fixes and security hardening in newer releases. Running an unpatched Terraform binary in CI/CD or with access to sensitive cloud credentials is a real risk, especially in regulated environments.
- Community and tooling alignment. Tools like Terragrunt, Checkov, Infracost, and Spacelift continuously update their support around current Terraform releases. Staying several versions behind can mean incompatibility with the broader IaC tooling ecosystem.
Note: Newer Terraform versions (starting in the 1.5.x timeframe) are released under HashiCorp’s Business Source License (BUSL), which comes with additional restrictions for some commercial use cases. If you prefer a community-governed, truly open-source option, OpenTofu is a fork of Terraform 1.5.6 maintained under the Linux Foundation, and it is largely compatible with existing Terraform workflows. Spacelift supports both Terraform and OpenTofu, so the tfenv/Terraform upgrades covered in this post fit neatly into your broader IaC strategy either way.
How to upgrade Terraform to the latest version with tfenv
Let’s follow the steps below.
Step 1 - Install tfenv and verify tfenv installation
Before we go into the installation part of tfenv let’s first see what tfenv is.
tfenv is a versioning tool for Terraform, maintained by the open source community on GitHub, under the MIT Open Source License. Keep in mind, it is not an official tool by HashiCorp.
Installing tfenv on MacOS
Let’s first see how to install tfenv on macOS. For macOS, we will use Homebrew. Refer to the following command for installation:
$ brew install tfenvInstalling tfenv on Linux
Installing on Linux is more manual. Use the following installation instructions:
- Clone the GitHub repo
$ git clone https://github.com/tfutils/tfenv.git ~/.tfenv- Update $PATH
$ echo ‘export PATH=”$HOME/.tfenv/bin:$PATH”‘ >> ~/.bash_profile- Create a symlink
$ sudo ln -s ~/.tfenv/bin/* /usr/local/binInstalling tfenv on Windows
tfenv officially lists Windows (64-bit) support, but it’s only tested in Git Bash and may still run into symlink issues. In practice, most teams either use WSL (Windows Subsystem for Linux) and follow the Linux instructions, or manage Terraform versions via other tooling on Windows and reserve tfenv for macOS/Linux build agents.
If you try tfenv on native Windows Git Bash, be prepared for occasional rough edges.
Verify tfenv installation
Whether you are on MacOS or Linux, you can verify the installation of tfenv by simply running the following command:
$ tfenv -vIt should print a tfenv version, for example, tfenv 3.0.0 or similar. The exact number isn’t important, as long as the command succeeds without errors.
If you want to check the latest tfenv release, you can always look at the GitHub releases page.
Step 2 - List available Terraform versions using tfenv
Now that we have seen how to install tfenv, let’s dig into the tfenv commands. The first command that we are going to see is
$ tfenv list-remote
The above command will list out all available versions of Terraform to date. Here’s a screenshot after running the tfenv list-remote command.
If you are looking for a specific version of Terraform (e.g., v0.12, v0.13, v0.14, v0.15) but tfenv list-remote returns a really long list of versions, you can run the following command that includes the version you want.
If you’re looking for a specific major/minor line, you can pipe the output through grep. For example, to find the 0.12.0 release:
tfenv list-remote | grep 0.12.0
Replace 0.12.0 with the major/minor you’re targeting (for example, 1.13. or 1.10.).
Step 3 - Upgrade to a specific Terraform version using tfenv
You have seen in the previous steps how to install tfenv and how to list all or some specific version of Terraform.
Let’s install a specific version (0.12.0) of Terraform using tfenv. Use the following tfenv for installation:
$ tfenv install 0.12.0
After installing Terraform 0.12.0, you need to run one more command to actually use that version:
$ tfenv use 0.12.0
Verify the installation of Terraform by running
$ terraform -v
Note: the above-mentioned command can be used for any version of Terraform , e.g. 0.13.0, 0.14.0, 0.15.0
Use version constraints with tfenv
If your configuration has a terraform block with required_version, tfenv can read that and choose an appropriate version automatically. For example:
terraform {
required_version = ">= 1.5, < 1.15"
}
You can then let tfenv pick a version that satisfies this constraint:
# Install the minimum required version
tfenv install min-required
# Install the latest allowed version
tfenv install latest-allowed
This makes it much easier to keep multiple projects on compatible versions without hard-coding a specific Terraform release everywhere.
Step 4 - Upgrade to the latest Terraform version using tfenv
In the previous step we saw how to upgrade to a specific version of Terraform, but what if you want to upgrade to the latest version irrespective of any specific one?
Well, tfenv provides the latest flag which can be used along with the $ tfenv install command and it will let you install the latest stable version of Terraform.
Here is the tfenv command for installing the latest version of Terraform (as of writing this article):
$ tfenv install latest
To switch and use the latest version of Terraform, run:
$ tfenv use 1.0.8
Verify the installation by running the $ terraform -v command:
Step 5 - Install and switch to a specific version using tfenv
In the previous steps, we have seen how to install specific versions (0.12.0) as well as the latest version of Terraform.
Let’s now see how to install and switch to some other version, 0.13.0 for example.
tfenv always requires you to first install the version of Terraform you want (if you haven’t already), then switch to that version.
First, install Terraform version 0.13.0:
$ tfenv install 0.13.0
Then, make the switch to 0.13.0 (if you have already installed other versions of Terraform, you can make direct use of the tfenv use command):
$ tfenv use 0.13.0
Note: the above-mentioned steps can be used for switching to any desired version of Terraform. Learn more about how to manage different Terraform versions.
Step 6 - Uninstall the Terraform version using tfenv
Last but not least, tfenv provides you with a feature to uninstall any version of Terraform. To uninstall any version of Terraform, you must provide the exact version (e.g. latest, 0.15.0, 0.14.0 etc.).
Here’s how to uninstall the latest version of Terraform:
$ tfenv uninstall latest
To uninstall a specific version of Terraform, such as 0.12.0, run
$ tfenv uninstall 0.12.0
How to upgrade Terraform providers with terraform init -upgrade
Upgrading the Terraform core binary via tfenv is only half the story. Your configuration also depends on providers (the plugins that communicate with AWS, Azure, GCP, and others), and those need to be upgraded separately.
Terraform locks provider versions in a .terraform.lock.hcl file on the first terraform init run. This ensures consistent versions across your team and CI pipelines, but the lock file won’t update on its own.
Running terraform init -upgrade tells Terraform to re-evaluate all provider requirements and update the lock file to the latest version that satisfies your constraints:
terraform init -upgradeIt won’t blindly install the latest release of every provider. With a constraint like ~> 5.0, it will upgrade to the latest 5.x release but never jump to 6.0.
After running the command, review the diff in .terraform.lock.hcl before committing. Treat it like any other dependency bump: check the provider changelog, look for breaking changes, and test before merging.
Note: terraform init -upgrade upgrades providers only. To upgrade the Terraform binary itself, use tfenv as described above.
How to plan a safe Terraform upgrade
Swapping the binary is the easy part. Making sure your infrastructure survives the change takes more thought. Before upgrading:
- Read the official upgrade guides for every major version you’re crossing. HashiCorp documents breaking changes in detail — don’t skip this step.
- Upgrade incrementally. If you’re coming from a pre-1.0 release, don’t jump straight to 1.11. Go 0.12 → 0.13 → 0.14 → 0.15 → 1.x, one step at a time.
- Test in a non-production workspace first. Run
terraform planagainst your staging environment with the new version before touching production. Look for warnings — they’re often previews of future breaking changes. - Pin your provider versions. Before upgrading Terraform core, lock your provider versions in
required_providersso the upgrade doesn’t also silently pull in a new provider version. - Use
required_versionconstraints. Add arequired_versionblock to your configuration so that teammates and CI systems can’t accidentally run the wrong Terraform version against your code:
terraform {
required_version = ">= 1.9, < 2.0"
}If you’re managing many stacks across teams, tools like Spacelift let you centrally enforce which Terraform version each stack runs — so upgrades become a deliberate, reviewable change rather than a one-off local experiment.
How to manage Terraform resources with Spacelift
Managing Terraform versions is one piece of the puzzle. But to achieve an end-to-end, secure GitOps workflow, you need a platform purpose-built to orchestrate your Terraform runs. Spacelift takes Terraform management to the next level with a powerful CI/CD workflow and features such as:
- Policy as code — Using Open Policy Agent (OPA), you can control how many approvals a run requires, which resources can be created, what parameters those resources can have, and what happens when a pull request is opened or merged.
- Multi-IaC workflows — Combine Terraform with Kubernetes, Ansible, OpenTofu, Pulumi, and CloudFormation. Create dependencies among them and share outputs across stacks.
- Self-service infrastructure — Use Blueprints to build Golden Paths for your teams. Developers complete a simple form to provision infrastructure based on Terraform and other supported tools — no deep IaC knowledge required.
- Third-party integrations — Integrate your favorite tools and build policies around them. For example, you can embed security tools directly into your workflows using Custom Inputs.
- Drift detection and remediation — Spacelift continuously monitors your environments for discrepancies between live infrastructure and your declared infrastructure as code, and lets you trigger automatic reconciliation to resolve detected drift.
Spacelift also lets you create private workers inside your own infrastructure, so you can execute workflows within your security perimeter. See the documentation for more on configuring private workers.
To learn more about Spacelift, create a free account today or book a demo with one of our engineers.
Key points
tfenv is a great tool to utilize when you are managing multiple environments that might have different versions of Terraform. With the help of tfenv, you can try out as well as install different versions of Terraform, and with the tfenv use command you can easily switch between the various versions of Terraform.
Terraform management made easy
Spacelift effectively manages Terraform state and more complex workflows, and supports policy as code, programmatic configuration, context sharing, drift detection, resource visualization, and many more features.
Frequently asked questions
How do I safely upgrade Terraform across environments?
Upgrade incrementally, starting with development and working up to production, and run terraform plan at each stage to catch issues before they reach live infrastructure. Use required_version constraints in your configuration to ensure every environment uses the intended version.
What breaks when upgrading Terraform versions?
The most common issues are deprecated syntax, changed provider behavior, and state file incompatibilities when crossing major versions. Always check HashiCorp’s official upgrade guide for the version you’re targeting, breaking changes are documented there.
Is it safe to upgrade Terraform in production?
Yes, if you’ve tested the same version against a staging environment using the same configuration and state structure first. Never upgrade the Terraform binary directly in production without a tested rollback plan.
How do I list available Terraform versions?
Run tfenv list-remote to see all available versions, or pipe the output through grep to filter for a specific release line. For example, tfenv list-remote | grep 1.11.
How do I install a specific Terraform version?
Run tfenv install 1.11.0 to install a specific version, then tfenv use 1.11.0 to switch to it. Verify the active version with terraform -v.
