Terraform/tfenv Installation Instructions
Infrastructure as Code (IaC) has become essential nowadays. Of course, there are various benefits, such as managing configurations through code, reducing the burden of manual setups, and mitigating the risks of human error. It seems that during external audits, there are cases where they check whether your infrastructure is managed using IaC as part of the review process. Perhaps auditors prefer to review infrastructure through code because it makes their job easier? (Though that's just speculation.)
If you're planning to build your application's infrastructure on the cloud, I strongly recommend using IaC unless you have a compelling reason not to. Besides the auditing aspect I mentioned earlier, if you manually build your infrastructure and then later decide, "I want to manage this with IaC after all," you'll need to be prepared for the challenges that come with that decision.
In this article, I'll provide installation instructions and a simple guide for those considering using Terraform.
Additionally, in real-world scenarios, it's common to specify a particular version of Terraform. I'll also introduce the installation steps for tfenv
, a tool that allows you to easily switch between Terraform versions for different projects.
Let's start your Terraform journey
Target Audience
This article is intended for Mac users. Windows users, please refer to the instructions on the official GitHub repository:
Installation Instructions
tfenv
You can install tfenv
via homebrew
. Open your terminal and run the following command:
brew install tfenv
After the installation is complete, run the following command. If the version number is displayed, the installation was successful:
tfenv -v
tfenv 3.0.0
With this, you’re ready to use Terraform.
Frequently Used tfenv Commands
tfenv list-remote
tfenv
is a tool that allows you to flexibly switch between different versions of Terraform on your machine. By running the following command, you can display a list of available Terraform versions:
tfenv list-remote
1.9.5
1.9.4
1.9.3
...
The versions displayed are those provided by tfenv
, and you can specify and use the version you need from this list.
tfenv list
To check the versions of Terraform installed on your machine, use this command:
tfenv list
* 1.9.4 (set by /usr/local/Cellar/tfenv/3.0.0/version)
1.9.2
1.6.5
The version marked with *
is the one currently in use. You can also confirm this with the terraform
command:
terraform -v
Terraform v1.9.4
tfenv use
When you want to switch to a different version, use the use
command. For example, to use version 1.9.5, run the following:
tfenv use 1.9.5
No installed versions of terraform matched '1.9.5:^1.9.5$'. Trying to install a matching version since TFENV_AUTO_INSTALL=true
Installing Terraform v1.9.5
Downloading release tarball from https://releases.hashicorp.com/terraform/1.9.5/terraform_1.9.5_darwin_amd64.zip
##################################################################################################### 100.0%
Downloading SHA hash file from https://releases.hashicorp.com/terraform/1.9.5/terraform_1.9.5_SHA256SUMS
Not instructed to use Local PGP (/usr/local/Cellar/tfenv/3.0.0/use-{gpgv,gnupg}) & No keybase install found, skipping OpenPGP signature verification
Archive: /var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T/tfenv_download.XXXXXX.WZIlUFPw7l/terraform_1.9.5_darwin_amd64.zip
inflating: /usr/local/Cellar/tfenv/3.0.0/versions/1.9.5/LICENSE.txt
inflating: /usr/local/Cellar/tfenv/3.0.0/versions/1.9.5/terraform
Installation of terraform v1.9.5 successful. To make this your default version, run 'tfenv use 1.9.5'
Switching default version to v1.9.5
Default version (when not overridden by .terraform-version or TFENV_TERRAFORM_VERSION) is now: 1.9.5
If the specified version is not installed on your machine, it will automatically download it from the remote repository and switch to that version.
You can also check the Terraform version:
terraform -v
Terraform v1.9.5
As you can see, you can easily switch between versions, making it convenient to manage different versions for different projects.
This concludes the installation instructions for tfenv
and an introduction to some commonly used commands. As mentioned at the beginning, if you’re planning to build cloud infrastructure, I highly recommend using IaC unless there’s a specific reason not to.