Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

Course End Project 1

Automating
Infrastructure
using Terraform

PG DO - DevOps
Akshay 01-Oct-2023
Certi caion

1
fi
Automating Infrastructure using Terraform

Contents
1. Introduction to the Project …………………………………….. 3

2. Installation of pre-requisites/tools ……………………………. 4

3. Execution of the Project ……………………………………….. 6

4. Project Results …………………………………………………. 15

5. Conclusion ……………………………………………………… 17

2
Automating Infrastructure using Terraform

1. Introduction

Objective: Use Terraform to provision infrastructure

Description: Infrastructure automation is critical. We tend to put the most


emphasis on software development processes, but infrastructure
deployment strategy is just as important. Infrastructure automation not
only aids disaster recovery, but it also facilitates testing and development.

Terraform is a tool that allows you to provision various infrastructure


components.

Project Goal: 1. Launch an EC2 machine using Terraform.


2. Connect to the instance.
3. Install Jenkins, Java and Python in the instance

Tools Required: Terraform, AWS account with security credentials

3
Automating Infrastructure using Terraform

1. Pre-requisites
1.1. Install Terraform

Terraform is installed and the version installed can be seen by using the
command

terraform —version

1.2. Create user with admin access and create access key and secret
access key

Open the AWS account and select IAM (Identity Access Management) and under
users, click on Create user and create user with administrator permissions as seen
below.

4
Automating Infrastructure using Terraform

Administrator permission policy is selected

Once the user is created, select the user and go to security credentials tab and
create access key and secret access key

5
Automating Infrastructure using Terraform

3. Execution of the Project


3.1. Launch an EC2 instance using Terraform

Open the terminal in your machine and create a directory and move into the
directory

mkdir project1
cd project1

Create a terraform le and enter the region, access key and secret key as seen
below

vi ec2.tf

6
fi
Automating Infrastructure using Terraform

Open the same le

Now to the same le add the resources of the instance like the AMI ID, instance
type and instance name as seen below

7
fi
fi
Automating Infrastructure using Terraform

Press :wq and save the le to exit and come out of the le

In the terminal initiate terraform using the below command

terraform init

8
fi
fi
Automating Infrastructure using Terraform

After initiation plan the resources using the below command

terraform plan

After planning now apply using the below command

terraform apply - -auto-approve

9
Automating Infrastructure using Terraform

You can see in the below screenshot that the apply is complete and instance is
created.

You can verify the creation of instance by going to the AWS account. You can see
that the instance with the same name Project-machine is created

10
Automating Infrastructure using Terraform

3.2. Connect to the Instance

Select the created instance and click on the connect button on the top. On the
next screen click on Connect button.

The EC2 instance is now connected.

11
Automating Infrastructure using Terraform

3.3. Install Python, Java and Jenkins.

To install Python execute the below commands

sudo su
apt update -y
apt install python3 -y

To install Java execute the below commands.

sudo apt-get install default-jdk -y

12
Automating Infrastructure using Terraform

To install Jenkins run these below commands

curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee \

/usr/share/keyrings/jenkins-keyring.asc > /dev/null

echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \

https://pkg.jenkins.io/debian-stable binary/ | sudo tee \

/etc/apt/sources.list.d/jenkins.list > /dev/null

apt update -y

Install Jenkins

sudo apt-get install jenkins -y

service jenkins start

13
Automating Infrastructure using Terraform

14
Automating Infrastructure using Terraform

4. Project Results
1. An EC2 instance was created using Terraform

15
Automating Infrastructure using Terraform

2. EC2 instance was connected

3. On the instance Python, Java and Jenkins were installed.

16
Automating Infrastructure using Terraform

5. Conclusion
Results shown in the previous section is evidence that the EC2 instance was
created using Terraform.

17

You might also like