Terraform from HashiCorp is provided as a command-line tool that must first be installed before it can be used. It’s provided as a single executable that can be downloaded and then used directly from the Windows Command Prompt or PowerShell. This means Terraform does not have a traditional Windows Installer application to install. It’s rather simpler than that. You basically download the executable (exe) and can run it where ever you are.
With Terraform distributed as a single executable file, it’s really easy to embed the
terraform.exe in a Git or other source code repository to include the Terraform version with the code for your Terraform project. However, it’s really convenient to have Terraform installed on your local machine, so you can just type
terraform in the Command Prompt or PowerShell directly to execute it.
Install Terraform on Windows
The following steps will guide you through installing HashiCorp Terraform on Windows and make it available to execute from any Windows Command Prompt or PowerShell prompt:
- Download the Terraform executable from HashiCorp. You can choose the supported version you wish to download from the official HashiCorp Terraform download page.
- Extract the downloaded
.zipfile from HashiCorp to the directory of your choosing to place the
terraform.exeexecutable on your machine. An easy to access location to extract Terraform to is
C:\terraform\or you can choose another folder on your machine that you desire.
- Update the System’s global path to include the location of the Terraform executable to make it available from anywhere on the Windows Command Prompt or in PowerShell. You can see instructions on updating the System’s global path below.
- Open a Windows Command Prompt or PowerShell window and run Terraform commands.
Check Terraform Install and Version
To easily check if Terraform is already installed, or even check which version is installed, run the following command:
If Terraform is installed, you will see the output of which version is installed. If not installed, then you will see the usual error that the Command Prompt or PowerShell are unable to find / run the command.
Update the System’s Global Path for Terraform
Downloading and extracting the HashiCorp Terraform executable to the local machine makes it available to use. However, you will need to specify the location of the executable every time you run a Terraform command unless you add the path to Terraforms location to the system’s global path within Windows.
The following steps will guide you through updating the System’s global path to include Terraform so it’s made available to the Windows Command Prompt and PowerShell prompts:
- Open the Advanced System Settings. This can be found by searching within the Windows Control Panel, or by searching for it within the Start Menu search feature.
- Click the Environment Variables… button.
- On the Environment Variables dialog, locate and select Path under System Variables, then click the Edit button.
- On the Edit environment variable dialog, click the New button, enter the path to where Terraform is located (such as
C:\terraform), then click the OK button to save it.
- Click OK on the Environment Variables dialog to close it.
- To test, open the Command Prompt or PowerShell and run
terrafrom versionor any other Terraform command from any folder / directory location.