Launch Web Server with Terraform On AWS

Arpit Sironiya
4 min readAug 31, 2020

Description of the Task

Task : Have to create/launch Application using Terraform

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

2. Launch EC2 instance.

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

4. Launch one Volume (EBS) and mount that volume into /var/www/html

5. The developer has uploaded the code into the GitHub repo also the repo has some images.

6. Copy the GitHub repo code into /var/www/html

7. Create an S3 bucket, and copy/deploy the images from GitHub repo into the s3 bucket and change the permission to public readable.

8 Create a Cloudfront using s3 bucket(which contains images) and use the Cloudfront URL to update in code in /var/www/html

******************************************************************

This is “task1” folder in which I have instance.tf file as shown below:-

This is “instance.tf” file code as shown below:-

First, we run “terraform init & terraform validate ” command as shown below:-

then run “terraform plan ” command as shown below:-

by running “ terraform plan” command we saw all code working fine:-

Now, We run “ terraform apply - -auto-approve

Now, at last, we get the output of instance public IP as also shown below:-

So, “security_grp1” is created successfully as shown below:-

The instance is also created:-

Also attached one other EBS volume with the instance as shown below:-

This is the file which is present inside the instance as shown below:-

Terraform code also created s3 which is used to store images which we used in the webpage:-

Terraform code also create CloudFront Distribution as also shown below:-

So Finally, this is the output as shown below:-

One command “ terraform destroy - -auto-approve ” and all Infrastructure delete

********************THANKS********************

--

--

Arpit Sironiya

Ansible / Flutter / Hybrid Multi-Cloud / GCP / EKS / Kubernetes / DevOps / MlOps / Docker Expertise / RHCSA / Advance JAVA / Python Learner / Arth Learner