DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Low-Code Development: Leverage low and no code to streamline your workflow so that you can focus on higher priorities.

DZone Security Research: Tell us your top security strategies in 2024, influence our research, and enter for a chance to win $!

Launch your software development career: Dive head first into the SDLC and learn how to build high-quality software and teams.

Open Source Migration Practices and Patterns: Explore key traits of migrating open-source software and its impact on software development.

Related

  • Terraform Tips for Efficient Infrastructure Management
  • Practical Use Cases With Terraform in Network Automation
  • Infrastructure as Code (IaC) Tools, Part 1: Overview of Tools
  • Master AWS IAM Role Configuration With Terraform

Trending

  • Partitioning Hot and Cold Data Tier in Apache Kafka Cluster for Optimal Performance
  • Difference Between App Development and IaC CI/CD Pipelines
  • Explainable AI: Seven Tools and Techniques for Model Interpretability
  • From JSON to FlatBuffers: Enhancing Performance in Data Serialization
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. How To Manage Terraform Versions

How To Manage Terraform Versions

Tenv is a version manager for Terraform, OpenTofu, Terragrunt, and Atmos. In one command it can detect and install the Terraform version without any actions.

By 
Alexander Sharov user avatar
Alexander Sharov
·
Jun. 19, 24 · Tutorial
Like (3)
Save
Tweet
Share
2.6K Views

Join the DZone community and get the full member experience.

Join For Free

The simplest method for handling Terraform versions is to tenv. tenv is a version manager for Terraform, OpenTofu, Terragrunt, and Atmos, which are written in Go. This versatile version manager simplifies the complexity of version control, helping to avoid spending time on IaC tools’ version management and ensuring developers and DevOps can focus on what is important the most — crafting innovative products and driving business value.

Why Do I Need Terraform Version Manager?

Managing a single Terraform project makes installing, upgrading, or switching to tools like OpenTofu straightforward. However, handling multiple projects with different Terraform versions can be challenging. Regular upgrades and tool switches require careful coordination to maintain functionality and stability across projects. The list of key challenges:

  • Version compatibility: Different projects may need specific Terraform versions, which might not be backward compatible.
  • Dependency management: Dependencies for each project must match the Terraform version of that project.
  • Environment consistency: It becomes challenging to maintain consistency throughout the development, staging, and production environments.
  • Tooling and integration: Various Terraform versions may require modifications to CI/CD pipelines and integrations.

tenv Terraform version manager covers all described challenges under the hood in a single binary that helps to manage Terraform versions transparently.

Tenv Version Manager Installation

MacOS

Shell
 
brew install tenv


Windows

Shell
 
choco install tenv


Linux

For Linux, you can install the tenv version manager via packaged binaries (.deb, .rpm, .apk, pkg.tar.zst , .zip or .tar.gz format) by visiting the release page or by apk/yay/snap/nix package managers. To get more information about the Linux tenv installation, check README.md.

Manage Terraform Versions via Tenv Version Manager

terraform version

Manage Terraform Version Like a Pro

Once you have the tenv version manager installed, you can use it to install specific versions of Terraform. To install Terraform, do the following steps:

Open a terminal, go to the directory with Terraform code (if you have any), and execute the following command to install Terraform version:

Shell
 
$ tenv tf install
No version files found for Terraform, fallback to latest strategy
Fetching all releases information from https://releases.hashicorp.com/terraform/index.json
Found compatible version remotely : 1.8.5
Installing Terraform 1.8.5
Fetching release information from https://releases.hashicorp.com/terraform/1.8.5/index.json
Downloading https://releases.hashicorp.com/terraform/1.8.5/terraform_1.8.5_darwin_amd64.zip
Downloading https://releases.hashicorp.com/terraform/1.8.5/terraform_1.8.5_SHA256SUMS
Downloading https://releases.hashicorp.com/terraform/1.8.5/terraform_1.8.5_SHA256SUMS.sig
Downloading https://www.hashicorp.com/.well-known/pgp-key.txt
Installation of Terraform 1.8.5 successful


Based on .tf code, the tenv version manager automatically detects and installs the necessary version of Terraform.  If no version is detected in sources, the latest version will be installed.

On the other hand, if necessary, a specific Terraform version can also be installed. Let's try to install Terraform 1.5.7:

Shell
 
$ tenv tf install 1.5.7
Installing Terraform 1.5.7
Fetching release information from https://releases.hashicorp.com/terraform/1.5.7/index.json
Downloading https://releases.hashicorp.com/terraform/1.5.7/terraform_1.5.7_darwin_amd64.zip
Downloading https://releases.hashicorp.com/terraform/1.5.7/terraform_1.5.7_SHA256SUMS
Downloading https://releases.hashicorp.com/terraform/1.5.7/terraform_1.5.7_SHA256SUMS.sig
Downloading https://www.hashicorp.com/.well-known/pgp-key.txt
Installation of Terraform 1.5.7 successful


The install command also supports version constraints such as:

  • latest : the latest available stable version
  • latest-pre : the latest available version, including unstable ones
  • latest-allowed or min-required: tenv will scan your Terraform files to detect which version is maximally allowed or minimally required.

As the last step, verify the Terraform version. To do it, use the following command:

Shell
 
$ terraform version
Terraform v1.8.5
on darwin_amd64


That's it. No symlinks, additional commands, or custom downloads are required. To read about more installation cases for Terraform, you can check the official README.md file.

Support Us, Contact Us

If you like this post, support us, download tenv, try to use it, and give us feedback on our official discussions channel! 

Press a star on GitHub if you like the tenv version manager.

Version control Terraform (software)

Published at DZone with permission of Alexander Sharov. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Terraform Tips for Efficient Infrastructure Management
  • Practical Use Cases With Terraform in Network Automation
  • Infrastructure as Code (IaC) Tools, Part 1: Overview of Tools
  • Master AWS IAM Role Configuration With Terraform

Partner Resources


Comments

ABOUT US

  • About DZone
  • Send feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: