Web Development on Aws using 
Terraform

Web Development on Aws using Terraform

In this article we will see how to do web development on aws .For all configurations we will use terraform instead of doing manually.

Steps for writing terraform code :

1. First of all login to aws account with user credentials.

2. Create one Key pair in aws.

3. Create one security group in aws that allow all traffic .

4. Launch one ec2 instance that uses above created key pair and security group.

5. Create one ebs volume and attach that with ec2 instance.

6. Install all necessary softwares inside ec2 instance required for web development

7. Download the code from github into /var/www/html folder and mount it with ebs volume.

8. Create one s3 bucket and put a object inside that bucket.

9. After that create cloudfront of that s3 bucket and put the ip of cloudfront inside file present in /var/www/html.

10.Create one snapshot of ebs volume .

So we will follow all above steps to achieve our task.

Step 1 -> For login into aws account instead of giving our access key and secret key we can create one profile and used that profile to login.

No alt text provided for this image

Now terraform there has various providers for various platform.For aws it has provider called as aws.

No alt text provided for this image

here we have given region name ,profile containing credentials .

Step 2 -> After successful login into aws account we need to create one key pair .Terraform provide one resource name tls_private key it will create private key .After that we can create public key using resource called aws_key_pair.

No alt text provided for this image

In this we have created one dependency because if private key is not created then there is no means of public key .After created aws key pair we can save it in our system by using local_file resource provided by terraform.

No alt text provided for this image

Step 3 -> For creating security group in aws terraform provide resource named as aws_security_group.

No alt text provided for this image

here ingress is for incoming traffic while outgress for outgoing traffic.We have allowed only 80 and 22 port while all ports in outgress.

Step 4 & 6 -> For launching ec2 instance we need ami id and instance type.

No alt text provided for this image

Here we have used connection and remote_exec provisioner to connect to ec2 using saved private key and download all necessary software .

Step 5 & 7 -> We can create ebs volume by using aws_ebs_volume provided by terraform.

No alt text provided for this image

Step 6 -> Now we attach our ebs volume to ec2

No alt text provided for this image

here we have used force_detach = true because if we destroyed ebs using terraform we cant do till we have not declare it true.

No alt text provided for this image

here we have used null resource because provisioner always be a part of some resource and we do not want to create any resource so we have used null resource . We have mount our ebs to folder and then used git clone.

Step 8 -> Terraform provide aws_s3_bucket for creating bucket.

No alt text provided for this image

we have created s3 bucket with acl of public read which means anyone can access this bucket.Now we need to put object inside the s3 bucket.

No alt text provided for this image

here also we have given acl equals to public read due to same reason.

Step 9 -> For creating cloud front we have used aws_cloud_distribution resource.

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

here we have given name of countries which can see this s3 object using cloudfront ip in whitelist .And to see ip of cloudfront we have print it in the console using output resource.

Step 10 -> Terraform provide resource for snapshot also.

No alt text provided for this image

After all this we have successfully write code for web development in aws by terraform .

Now we need to run our code but before it we need to install all plugins required by terraform by using terraform init command.After that run terraform apply command.

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

We have successfully created our web development .Now just need to put this cloudfront ip inside file .

No alt text provided for this image

Now we can see our output with the public ip of ec2 instance.

No alt text provided for this image

After all this we can delete all the resources of Aws by one click

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

we have successfully deleted all resources from aws.

Hope this article will be useful in getting some knowldege.

Thanks

Hritick Goyal



要查看或添加评论,请登录

Hritick Goyal的更多文章

  • Monitoring VM Using Prometheus

    Monitoring VM Using Prometheus

    In this article we will see how we can deploy Prometheus and Grafana server in kubernetes and how to use it for…

  • Jenkins Image & deployment pipline

    Jenkins Image & deployment pipline

    In this article we will see how to create a jenkins image and how to use that image for building a deployment pipeline.…

  • Deploying App on AWS EKS (Elastic Kubernetes Service )

    Deploying App on AWS EKS (Elastic Kubernetes Service )

    In this blog i will explain how to use amazon eks service to deploy app . First it is good to know what is eks service.

  • Integration of Machine Learning models with jenkins (MLops)

    Integration of Machine Learning models with jenkins (MLops)

    In this article i will explain you how we can integrate machine learning model with devops (jenkins) These are the…

  • Face Recognition using transfer learning

    Face Recognition using transfer learning

    I am writing this article to explain all the things which can used for face recognition using transfer learning…

  • First task of Devops assembly line Training

    First task of Devops assembly line Training

    I have just completed my first task in devops assembly line training under Vimal Daga sir. The task was to create end…

社区洞察

其他会员也浏览了