Deploying webserver on AWS cloud using Terraform

Vanshita Mittal
3 min readAug 9, 2020

--

Finally , I completed Task 1 of Hybrid Multi cloud given by Vimal Daga sir .

Terraform :

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 solutions.

TASK :

1. Create the key and security group which allow 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. Developer have uploded the code into github repo also the repo has some images.

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

7. Create 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

Prerequisite :

  1. AWS CLI — should be configured
  2. Terraform CLI

STEPS:

  1. Create Key :

2. Create provider for terraform :

provider “aws” {
region = “ap-south-1”
profile = “profile_name”
}

3. Create Security Group :

4. Create Instance :

5. Launch EBS Volume :

resource “aws_ebs_volume” “ebs_vol” {
availability_zone = aws_instance.os.availability_zone
size = 1

tags = {
Name = “mypd”
}
}

6. after Launch , attach it with instance :

7. Create a Webpage and upload it into github , As HardDisk is created , Now to partitioned and mount it :

provisioner “remote-exec” {
inline = [
“sudo mkfs.ext4 /dev/xvdf”,
“sudo mount /dev/xvdf /var/www/html”,
“sudo rm -rf /var/www/html/*”,
“sudo git clone
https://github.com/VanshitaMittal/HyTask1.git /var/www/html/”
]

}

8. For S3 Bucket and CloudFront :

9. Firstly run this command to initialise plugins :

terraform init

10. then use this command to run all above code :

terraform apply

after this :

Instance is created ….

volumes is created ….

cloudfront ….

Webpage :

11. Now , to delete everything using this command :

terraform destroy

Task is completed !!

Thanks !!!!!!

--

--

No responses yet