How to Install & Configure Terraform on Ubuntu

Terraform is an infrastructure as a code platform(IaaC) developed by HashiCorp. We can simply write code in the human-readable format following HashiCorp Configuration Language (HCL) and deploy it to get the infrastructure in the cloud. Terraform is supported in many cloud providers like Google, Amazon, Alibaba, etc.

 

 

  • Download the latest version of Terrafrom.

 

wget https://releases.hashicorp.com/terraform/0.14.3/terraform_0.14.3_linux_amd64.zip

 

  • Unzip the download file.

 

sudo apt install zip -y

                sudo unzip terraform_0.14.3_linux_amd64.zip

 

  • move terraform to /usr/local/bin/ to execute the command.

 

sudo mv terraform /usr/local/bin/

 

  • Check the version.

 

terraform version

 

  • Once Terraform is installed,then create a folder.

 

mkdir project

 

  •    Go to project directory and create files:-

vim main.tf    (creates all the resources)

vim variables.tf  ( define the variables type and optionally set a default value)

vim outputs.tf (store the results of a module operation)

 

  • Initializing terraform will make the necessary configuration. So, execute the following command.

 

terraform init

 

  •  Deploy the code.

 

terraform apply 

 

  • Destroy the above infrastructure.

 

terraform destroy

 

Leave a Reply