Terraform: Installation guide for beginners

Introduction:

Terraform is a tool for building, changing and versioning infrastructure safely and efficiently. Terraform can manage existing and popular service providers as well as custom in-house solution. 

We need to install the following packages if not installed already:

#yum install unzip -y

#yum install wget -y

2: Go to the https://releases.hashicorp.com/terraform/link to check the latest available version to download,in my case latest available version is 0.11.7 

#wget https://releases.hashicorp.com/terraform/0.11.7/terraform_0.11.7_linux_amd64.zip

2.1: Let’s extract the downloaded zip terraform package:

2.2: Copy the extracted file to /usr/loacl/sbin and verify terraform installed version

3: Here we have installed terraform on linux box, let’s apin up first our Ec2 instance using terraform. First we need to setup the aws provider by creating the 3files- aws.tf, variable.tf and terraform.tfvars

aws.tf => This will configure the provider for aw, it uses string interpolation to pull variable from variable.tf file.

variable.tf => This file is typically full of environment specific configuration.

terraform.tfvars => This file will pass into each command and provides the secret and more specific values.

Run the “terraform init” command to initialize the provider plugins:

Once this check is passed, we are good to create our first terraform code to launch an Ec2 instance in aws:

We are using basic specification just to test the setup:

Let’s verify the written code by “terraform plan” command:


As we did not see any error while executed “terraform plan” command so we are good.

Let’s not wait anymore and spin up the instance using “terraform apply” command:


Yes, so here we have launched our first Ec2 Instance using terraform.

Thank you for reading the article!

Hope you liked the post, we wish you best of luck, stay tuned and keep learning!

Leave A Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.