Installing Terraform on Windows and Linux

Shrihari Haridas
3 min readApr 29, 2023

--

A. For Windows Steps are following

  1. In the AWS Management Console search bar, enter EC2, and click the EC2 result under Services:

2. On the left-hand side, click on Instances.

3. Right-Click on the Windows EC2 instance and click Connect:

4. Ensure the Session Manager tab is selected and click the Connect button:

A PowerShell command prompt should appear:

5. Use the following commands to make a new directory for Terraform on the Windows Server:

mkdir C:\terraform
cd C:\terraform

The Terraform binary will be saved to this folder and live there while Terraform is being used on the server.

6. Download the Terraform binary using Invoke-WebRequest:

Invoke-WebRequest -Uri https://releases.hashicorp.com/terraform/0.13.4/terraform_0.13.4_windows_amd64.zip -outfile terraform_0.13.4_windows_amd64.zip

The Terraform zip file will start to download in the PowerShell session. This may take a minute or two:

7. Use Expand-Archive to extract the binary from the zip file and remove the zip file from the directory:

Expand-Archive -Path .\terraform_0.13.4_windows_amd64.zip -DestinationPath .\
rm .\terraform_0.13.4_windows_amd64.zip -Force

The Terraform directory now only contains the Terraform executable:

8. Set the Terraform directory as a PATH variable:

setx PATH "$env:path;C:\terraform" -m

Terraform needs to be set as an environment variable in order to be used in the command line without having to specify the path. If this part is not done, then the path would have to be included every time Terraform is used like in the example below:

9. Update the current PowerShell session with the new environment variable:

$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")

10. Confirm Terraform is installed:

terraform version

B. For Linux Steps are following

  1. In the AWS Management Console search bar, enter EC2, and click the EC2 result under Services:
  1. On the left-hand side, click on Instances.

3. Right-Click on the Linux EC2 instance and click Connect:

4. In the Session Manager tab, click the Connect button:

5. Change directory to home:

cd ~/

6. Use wget to download the Terraform zip file:

wget https://releases.hashicorp.com/terraform/0.13.4/terraform_0.13.4_linux_amd64.zip

7. Unzip the zip file using the unzip command:

unzip terraform_0.13.4_linux_amd64.zip

8. Move the terraform binary to the /usr/local/bin directory:

sudo mv terraform /usr/local/bin

9. Verify that Terraform is installed:

terraform version

--

--

Shrihari Haridas
Shrihari Haridas

Written by Shrihari Haridas

Hello everyone, I am Shrihari Haridas I am a Cloud & DevOps Engineer, I work with most of DevOps Tools like, Jenkins, Git, Docker, etc.!& for Cloud AWS

No responses yet