Purpose
This manual aims to establish the standardized procedure for the efficient installation and management of multiple versions of the framework Terraform using the tool tfenv. The ability to switch between versions is essential in multi-project environments or that require support for specific modules.
1. Introduction to tfenv
tfenv is a Terraform version manager (Terraform Version Manager), similar to tools like nvm (for Node.js) or pyenv (for Python).
Key Features
-
Quick Installation: Install any version of Terraform with a single command.
-
Dynamic Alternation: Change the global version of Terraform instantly.
-
Insulation by Project: Define a specific version of Terraform per project directory.
-
Compatibility: Ensure environment consistency across CI/CD pipelines and team environments.
2. Installation and Configuration of tfenv
2.1. Repository Cloning
Clone the repository tfenv in the directory home of the user (~/.tfenv).
git clone https://github.com/tfutils/tfenv.git ~/.tfenv2.2. PATH Configuration
Integrate the binary directory tfenv (~/.tfenv/bin) to the PATH system to make commands accessible.
echo 'export PATH=""$HOME/.tfenv/bin:$PATH""' >> ~/.bashrc
echo 'export PATH=""$HOME/.tfenv/bin:$PATH""' >> ~/.zshrcNote: After executing the command, it is necessary reload configuration shell to apply the changes.
-
For Bash:
source ~/.bashrc -
For Zsh:
source ~/.zshrc
23. Installation Verification
Confirm that tfenv has been installed successfully by running the version command.
tfenv --version3. Terraform Version Management
3.1. Version Installation
Use the command install to download and add specific versions to the local environment.
| Aim | Command |
| Install a specific version | tfenv install 1.7.5 |
| Install another version (example) | tfenv install 1.6.0 |
| Install the latest stable version | tfenv install latest |
3.2. Version List
| Aim | Command | Description |
| Check installed versions | tfenv list |
Shows the Terraform versions available locally. |
| See available versions | tfenv list-remote |
Lists all Terraform versions available in the HashiCorp registry. |
3.3. Global Version Switching
The command use activates the desired version of Terraform globally for the system.
tfenv use 1.7.5Verification: Confirm the active version globally:
terraform version4. Insulation by Project (Recommended)
Best practice in work environments is to lock in the Terraform version within the project, ensuring that all team members and CI/CD processes use the same one. release.
4.1. Version Definition
Inside the root directory of your project (where the files are located .tf), create a file called .terraform-version containing only the required version number.
# Ejemplo: Estandarizando la versión 1.7.5 para el proyecto
echo "1.7.5" > .terraform-version4.2. Automated Behavior
When you run any Terraform command or tfenv inside this directory, tfenv will automatically detect the file .terraform-version and:
- Will install the version if it is not present locally.
- will change to that version, temporarily overriding the global version of the system.
This file must be commissioned and uploaded to the repository to ensure uniformity across the team.
5. Maintenance
5.1. Update
To install and downgrade to the latest available version of Terraform:
tfenv install latest
tfenv use latest5.2. Uninstallation
To remove a version of Terraform that is no longer needed:
tfenv uninstall 1.6.0:wq!
Comments