Automating Terraform with Jenkins and Launch web application on AWS EC2 Instance

Automating Terraform with Jenkins and Launch web application on AWS EC2 Instance

No alt text provided for this image


Terraform is an open-source infrastructure as a code software tool created by HashiCrop. It enables users to define and provision a data center infrastructure using a high-level configuration language known as Hashicorp Configuration Language (HCL). Terraform supports a number of cloud infrastructure providers such as Amazon Web Services, IBM Cloud (formerly Bluemix), Google Cloud Platform, Digital Ocean Linode, Microsoft Azure, Oracle Cloud Infrastructure

Amazon Web Services (AWS) is a subsidiary of Amazon that provides on-demand cloud computing platforms and APIs to individuals, companies, and governments, on a metered pay-as-you-go basis. In aggregate, these cloud computing web services provide a set of primitive abstract technical infrastructure and distributed computing building blocks and tools

The task is given by #vimaldaga sir to launch a web application on EC2 instance by writing a terraform code. I have completed it by using AWS, Terraform, Jenkins, and GitHub

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

No alt text provided for this image


Jenkins is an awesome Continuous Integration tool which allows you to add multiple slaves as per your project requirement to a central Master server

I have created a master-slave configuration in Jenkins in which Redhat in the virtual machine serves as a master and the base os window is served as a slave

JOB1: run a terraform file

this file create an instance and attach EBS volume to it and mount with the folder /var/www/html and copy code from github to /var/www/html folder

terraform init - download the required plugins for the file

terraform apply - run the terraform file

No alt text provided for this image

STEP 1: Terraform Code to create security groups

No alt text provided for this image


STEP 2: Terraform Code to Launch Instance

No alt text provided for this image


STEP 3: Terraform code to Launch one Volume (EBS)

No alt text provided for this image

STEP4: Terraform code to mount that volume into /var/www/html and fetch code from Github and copy in the folder /var/www/html

No alt text provided for this image

JOB 2: Run terraform code

this file create a bucket and create a cloud with that bucket

This job is run after the 1st job as soon as 1st job successful 2nd Job run

No alt text provided for this image

terraform init - download the required plugins for the file

terraform apply - run the terraform file

No alt text provided for this image

Cloud front created using bucker


STEP1: Terraform code to create a bucket

No alt text provided for this image


STEP2: Terraform code to create cloud front

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

Job3: upload images in bucket

For this job, we have to download the plugin S3 publisher and go to manage Jenkins then go to configuration and give the details of your IAM user

No alt text provided for this image

this job fetches code from Github and uploads it on a bucket created in JOB2 and run after the JOB2 is successful

No alt text provided for this image

fetch code from Github and I am using pol SCM so that this job runs every minute and fetch code every minute

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

set the post built trigger and give the details of the bucket in which we want to upload the images

No alt text provided for this image

At last, after cloud Front created we can replace the code of images in web Html code with the links created in the cloud front of all images in the bucket.

if client excess the site from another country then he might face latency and images does nit load fast so we can replace the images of code from the cloud front link so that site load quickly

the final web application launch when we can put the IP of instance in the browser

All the images are coming from the Cloud front we created in JOB2

No alt text provided for this image

This is all about this project.

Thank you guys for reading this. This project was really a great learning experience for me and I learn true meaning how to integrate terraform with Jenkins

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

Mehul Kulshrestha的更多文章

社区洞察

其他会员也浏览了