Deploying WebServer Infrastructure on AWS with S3 implementation and Cloudfront using Terraform
Terraform:
Terraform is an open-source infrastructure as code software tool created by HashiCorp. It enables users to define and provision a data center infrastructure using a high-level configuration language known as Hashicorp Configuration Language, or optionally JSON.
Task overview:
Launch an EC2 instance having the required programs(git, Apache webserver, php) installed.
Enabling these services to be started on reboot.
Creating an EBS volume and mount it to the EC2 instance.
Creating a separate Security Group for this instance having the SSH and HTTP port exposed.
Clone the github repo content and copy it to /var/www/html.
Making an S3 bucket and attaching it to EC2 for static content.
Configuring geo-restrictions to global.
PreRequisite
- Download AWS CLI.
- Configure AWS.
- Configure the AWS profile.
- Download Terraform
Steps i follow for the task:
i wrote a code for
Setting up the region:
Creating a separate Security Group for this instance having the SSH and HTTP port exposed.
Creating an EBS Volume
Creating the EC2 instance and mouning EBS volume.
Cloning Github repo content to the EBS.
Creating S3 bucket and downloading public ip address.
Cloudfront distribution
finally save the file with .tf extension in a folder.
Code images
After writing and saving the code in a folder we have to run this code.so in cmd we have to go their where we store are .tf code file.than run these below commnad.
RUN COMMAND -
terraform init
terraform validate
terraform plan
terraform apply -auto-approve
after last command are website launch.
Finally my website launch:
some images from aws :
And its completed!!!