Install Terraform inside the Linux Machine – Terraform in GCP Compute Engine.

Now we know What is Terraform? The Next Step is to download and install the terraform inside the Linux server. If you are following me, then you know I create a brand-new Linux-based machine inside GCP Compute Engine. I installed Nginx also in it for the demo perspective. 

If you haven’t checked that article, then please take a look into it: Create a Linux based GCP compute inside the GCP console

 In this topic, I will install a terraform inside a Linux machine using the GCP compute engine.  As you already know that we created a Linux machine named terraform.  

Please follow the following steps to install the terraform on this Linux machine. 

The first step is to SSH into that terraform machine. Please check the image below and do the same. 



When you SSH into the Linux machine, this is the fresh look of the new device.



The second step is to update all the packages in the Linux machine using this command.

:sudo apt-get update 

 You can also use this command if you have centos. 

:sudo yum update 



The above commands in action will look as shown in the image below.



We need Wget to command to download the terraform from the link, and we copy in some time and Unzip command to unzip the downloaded terraform zipped file. For that, we need to check if those commands are available or not. If not, then we will install those commands first. 


As you see in the image below, we don’t have these commands available. 



The third step is to install wget and unzip using these commands. I wrote the command in which you can download both wget and unzip.  

:sudo apt-get install wget unzip 

 But you can write both commands separately, also as shown below. 

:sudo apt-get update wget 

:sudo apt-get install unzip 





The fourth step is to find the link of terraform, which you need to download inside your Linux machine. Open google and write download terraform, as shown in the image below. 




Click on the first link, and it will take you directly to the terraform download page.  





Find the Linux exe and right-click on the 64bit and click the copy link, as shown in the image below. 



The fifth step is to download the terraform using the wget command as shown below

: wget https://releases.hashicorp.com/terraform/0.13.2/terraform_0.13.2_linux_amd64.zip 


As I am writing this article, Terraforms 0.13.2 version is the latest version available on the terraform website.  



Check if it’s adequately downloaded or not using the command as shown below 

: ls –la 



Now unzip the zipped terraform using the unzip command as shown below

: unzip terraform_0.13.2_linux_amd64.zip 




The sixth step is to make a new downloads directory and move the unzipped terraform version in it, as shown below 

: mkdir downloads 

: mv terraform downloads 




The seventh step is to set the path of the terraform in our bash profile.  

Find out the profile using ls –la. 

Then open the .profile using Vim as shown below 

: vim ~/.profile 




In Vim, add this value 

: export PATH = ‘$Path:~/downloads’ 

To exit from Vim, press ESC first, then :wq and press enter it will save everything and let you escape from the Vim.




It will not automatically update the path for your current session, and for that, you need to do this final step that is to update your path using the source command. 

: source ~/ .profile 




Now check if terraform is installed or not using this terraform command 

: terraform 




So you saw step by step how we installed it inside a Linux-based machine. Now in the next few articles, I will show you how to create a Terraform project, setup service accounts inside GCP. Enable APIs inside GCP to work seamlessly with Terraform. Setting up a remote state in Google cloud storage, and we will use Google Cloud Storage instead of our local machine storage.



About the author