Creating an Infrastructure in AWS using Terraform

Gaurav Pagare

--

~ EBS + S3 + Cloud-front

Task overview :

So in this task I have tried to create an infraction totally end to end with terraform. This is what we call Infrastructure as Code. In this setup the code that developer pushes to the github is pulled in an ec2 instance which have the apache web services enabled. Also this ec2 instance is having an security group which allows port 80 and 22 . More over the code is stored in the folder which is basically mounted with an ebs volume so by chance we lose our ec2 instance in any case we can again recreate it with the terraform. the code that the developer have created also contains images and photos we are retrieving them from the cloud-front url which has its source as an s3 bucket although these thing are also created using the terraform code.

Steps To Achieve this setup:

1. Create the key and security group which allow the port 80.

2. Launch EC2 instance. In this Ec2 instance use the key and security group which we have created in step 1.

3. Launch one Volume (EBS- Volume) and attach it with the EC2- instance which we launch in step 2

4. Create S3 bucket, and copy/deploy the images into the s3 bucket and change the permission to public readable.

5. Create a Cloud-front using s3 bucket(which contains images) as the origin

6. mount the ebs-volume we attached to ec2 instance to /var/www/html/ folder further pull the Developers uploaded code from github repo here.

Now lets Begin …

1. Create the key and security group which allow the port 80.

Note: Here, I have already created and Downloaded the Key for ssh so I am using the same key again

2. Launch EC2 instance. In this Ec2 instance use the key and security group which we have created in step 1.
3. Launch one Volume (EBS- Volume) and attach it with the EC2- instance which we launch in step 2
4. Create S3 bucket, and copy/deploy the images into the s3 bucket and change the permission to public readable.

Note: I have not provided any acl to aws_s3_bucket so by default value will be taken i.e acl = private so the bucket is not public but the objects in it are public

5. Create a Cloud-front using s3 bucket(which contains images) as the origin
6. mount the ebs-volume we attached to ec2 instance to /var/www/html/ folder further pull the Developers uploaded code from github repo here.

Now Lets Run the terraform init so that all the plugins and required things will be installed in the terraform folder

Now Lets run the code i.e apply the code using Terraform apply

terraform apply total 8 stuff added

Now lets check our application and configured stuff on AWS portal

  1. final application
Final application. image coming form cloud-front and code from ebs-volume

2. Now Lets check the ec2-portal

These are the security group, ec2-instance and ebs-volume

3. Now lets check the s3 bucket and object

s3 bucket and object

4. Cloud-front

cloud-front

Hurry Our Task is done !!!!

Now Lets Clean Our environment …. using Terraform destroy

terraform destroy

Great, we have successfully done the task.

Hope You have Liked It

Thankyou For Reading : )

GitHub URL : Here

Any query and suggestion are always welcome — Gaurav Pagare

--

--

Gaurav Pagare

I am a passionate & dedicated guy aiming for achieving excellence in life. Exploring the latest technologies and tools. Passionate to learn those