This tasks comprises creation of the following codes in the terraform tool:

  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

To do the task i have started this project by creating a 4096 bits of SSH-2 RSA key using the putty generator.

After creating this key i saved this in both the format public key as well as the private key.

Copy the authorized key access and paste it in the public key argument.

Now i first write the code to make a key in the aws cloud using terraform tool.

After pasting the public key argument simply save the file in the .tf format and use terraform apply.

After creating the key i have created the security group which allow the ports 80 , 8080 and 22. to perform the specific work.

In these images i have set only the inbound or ingress rules

After creating the security group i have created one customized ami image on the base image of RHEL8 in the aws cloud in which i have installed github, jenkins, httpd , java so that they can be used for the further process.

For connecting to the instance we all need a key and everyone have diff keyname so in here i have created a variable which first asks for the keyname and then it will store it as a variable name and that variable can be used multiple times with diff values.

And also I have created one EBS volume to attach it on the instance

I have given name /dev/sdf to the attached hard disk and also for attaching the volumes we need the instance id and the volume id , here I have done the same work as what i have did to store the key name as a variable.

After completing this part I have created one s3 bucket and give an public-read access to it.

And then i stored the output of this bucket into different variables for further use. Like it zone id , region id etc. So that i can configure the Cloud front arguments using these variables.

Finally the complete terraform code it completed. Yes this code is lenghty though but its worth it. Becuse now onwards from one single command i’ll be able to do multiple things like creating a volume attaching it creating diff buckets giving diff permissions.

After running the “terraform apply” command give the keyname and it will start creating all the necessary infrastructure for running the webserver or any app.

All the outputs related to the instances, bucket , cdn , security group are given in these pictures.

These outputs can be verified from the webUI interface also.

After creating the infrastructure successfully, now we need to login to our instance. Here again I have used Putty to login via ssh. For login it requires the public ip of the instance which we can easily get from the cli we dont have to login to the aws account again and again. Also we use the private key which we initially generated.

After login to the ssh we first switch to the root user and mount the hard disk to the /var/www/html directory. But for this we need to first create the partitions in it ,then format it and then mount to that folder

After mounting the hard disc to the directory I have enabled the jenkins and httpd services. HTTPD is used for running the webserver and the best use of jenknins i ll tell you in the end. For now after enabling the services i have created the one job in jenkins which will copy the code from the github repository to the /var/www/html folder.

Now in this code to access the image i have created the S3 bucket and used cloud front service. Here the we can upload the data like video ,images etc to the s3 bucket and that can be accessed by the cloudfront front i.e we need to use the url which is given by the cloudfront to access that data.

And to access the website we need to use the public ip which is given by the instance.

It took approximately two days to write the complete code and for the creating the infrastructure it took less than 5 mins. This is the power of terraform. And also this complete structure can be disposed by writing one command.

Now the best case we can solve using this infrastructure is that we do not have to give any key to login to the system. We do not have to provide the port 22 to login in the webserver. As it will enhance the security. instead we can give the port no. 80 and 8080 just to use these services. And for updating the code we can use jenkins as we can update the code by uploading it to the repsitory and then it can be directly updated to our webpage.

Feel free to contact me in case of any doubt and suggest me to improve this project if needed.

For refrence use the github link. I’ll post all the screenshots and codes related to my github account.

LINKEDIN PROFILE:-https://www.linkedin.com/in/akshat-soni-011b461a6/

GITHUB URL:-https://github.com/akshat-crypto/HCC_Task1.git

Next Blog URL:- https://medium.com/@akshatsoni396/launching-an-app-server-using-terraform-2-b35119fec3dd




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Clone a private git repository using SSH

CSS: Day 9

Mobile navigation bar

Confusion of a Developer

Buildly CLI Tutorial

Flutter MethodChannel, Dart Generic and Type-Casting

Why Developers Should Appreciate Test- Driven Development and Not Shy Away From It!

How to Create Database Backup in Laravel

How to Create Database Backup in Laravel

How to Create Infrastructure as Code for AWS and Azure

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Akshat Soni

Akshat Soni

More from Medium

Do You Know Who Owns Your Domain?

Sustainable Cloud Architectures: Part 1

Javascript’s Map Data Structure

Securing Online Transactions