INFRASTRUCTURE AS A CODE USING AWS CLOUD(AMAZON WEB SERVICE) AND TERRAFORM TOOL BY HASHICORP

INFRASTRUCTURE AS A CODE USING AWS CLOUD(AMAZON WEB SERVICE) AND TERRAFORM TOOL BY HASHICORP

What is Terraform?

Terraform is a tool/software which enable a user to use multiple cloud just by writing a code. It alllows a programmer to use services of different cloud and make the product more useful. Instead of learning all the commands of multiple cloud, we have one way to use all the cloud to deploy our webapp/website/webserver etc and that way is known as terraform.

Task Description-

- Create a key and security group which allow the port 80. - Launch EC2 instance. -In this EC2 instance use the key and security group which we have created in step 1. -Launch one Volume (EBS) and mount that volume into /var/www/html. - Developer have uploaded the code into github repository also the repository has some images. -Copy the github repo code into /var/www/html. - Create S3 bucket, and copy/deploy the images from github repository into the s3 bucket and change the permission to public readable. -Create a Cloudfront using s3 bucket(which contains images) and use the Cloudfront URL to update in code in /var/www/html.


Now, let's see step by step procedure to do the above task !!

STEP 1- Login to your profile and mention the Provider over which terraform would work.A profile with name "dev" will be created after writing the credentials like Access key,Secret key etc.

No alt text provided for this image

provider "aws" tells us that terraform would work on aws cloud inside region "ap-south-1" and profile "dev"

No alt text provided for this image


STEP 2- Creating key pairs

No alt text provided for this image

Key with name "newoskey" would be created.

No alt text provided for this image
No alt text provided for this image

Key is successfully created..!

STEP 3- Creating security group which allow ssh and httpd protocol at port number 22 and 80 respectively.


No alt text provided for this image
No alt text provided for this image

Security group is created.!

STEP 4- Launching instance using key pair and security group created in step 2 and step 3. and Providing connection to instance launched. then Adding provisioner.

No alt text provided for this image
No alt text provided for this image


Providing connection is necessary because if we do not provide any connection to instance created then nobody would be able to communicate to our instance and instance will become useless.

Provisioner enable us to run any command which is required to perform our task. There are two types of provisioner - "remote-exec" and "local-exec". "remote-exec" helps us to run command on remote system while "local-exec" helps to run command on our local system.

In above provisioner, yum command is running to install httpd , php and github.

STEP 5- Creating persistent storage EBS of size 1 GB.

No alt text provided for this image
No alt text provided for this image

STEP 6- Attaching volume to our instance launched.

No alt text provided for this image

STEP 7- Mounting EBS volume onto /var/www/html folder and placing the code from github inside /var/www/html.

No alt text provided for this image
No alt text provided for this image

Code written in "index.html" is successfully copied into the directory /var/www/html. We can see the code by writing IP of instance launched.

STEP 8- Creating S3 bucket. and Connecting S3 bucket with github to access the media.

S3 bucket is created in which we place our media which we want to see on webserver.

No alt text provided for this image

"DSC_3110.JPG" image is present in my github repository. By creating bucket object, I have downloaded the image from github and placed it in S3 bucket.

Images is successfully downloaded in my bucket "my-tf-task-bucket" form gihub.

STEP 9- Creating cloud front and giving origin as s3.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Cloud front is a Content Delivery Network which allows the access of content of S3 bucket with less latency.

Cloud front provides "domain name" through we can access the S3 bucket content more rapidly.

DONE.!!!

Now , let's see implementation..

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

FINALLY DONE..!

SUCCESSFULLY CREATED A INFRASTRUCTURE USING AWS AND TERRAFORM..


THANKS FOR READING !!!


To view or add a comment, sign in

More articles by Prashant Tripathi

Explore content categories