Terraform

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. 

ssh-into-the-new-machine---paayi-terraform-tutorials

 

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

after-successful-login-into-ssh-this-screen-will-come---paayi-gcp-tutorials

 

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.

update-all-packages---h4c-terraform-tutorials

 

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. 

we-need-wget-and-unzip-and-its-not-there---paayi-terraform-tutorials

 

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 

 

 

install-unzip-and-wget-in-linux-machine-h4c-terraform-tutorials

 

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. 

now-search-download-terraform-in-google---paayi-terraform-tutorials

 

 

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

Download-terraform-page---go-down-and-search-linux-software---paayi-terraform-tutorials

 

 

 

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

right-click-on-64-bit-and-copy-the-link---paayi-terraform-tutorials

 

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.  

it-will-download-terraform---paayi-terraform-tutorials

 

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

: ls –la 

terraform-downloaded---paayi-terraform-tutorials

 

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

: unzip terraform_0.13.2_linux_amd64.zip 

 

unzip-downloaded-terraform---paayi-terraform-tutorials

 

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 

 

unzip-downloaded-terraform---paayi-terraform-tutorials

 

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 

 

need-to-declare-the-downloads-path-for-terraform-inside-your-machine-profile---paayi-terraform-tutorials

 

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.

 

add-this-line-inside-your-dot-profile---paayi-terraform-tutorials

 

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 

 

declare-source-for-terraform---paayi-terraform-tutorials

 

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

: terraform 

 

terraform-installed---paayi-terraform-tutorials

 

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

Home4Cloud