0% found this document useful (0 votes)
22 views25 pages

Terraform

This document details the integration of Terraform with AWS to provision a cloud infrastructure that includes an EC2 instance, an S3 bucket, and a custom VPC. It outlines the installation of Terraform, the configuration of the EC2 instance, VPC setup with public and private subnets, and the creation of an S3 bucket, emphasizing the benefits of Infrastructure as Code (IaC). The document provides specific Terraform commands and configurations for each component, facilitating automated and consistent cloud resource management.

Uploaded by

Anil Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views25 pages

Terraform

This document details the integration of Terraform with AWS to provision a cloud infrastructure that includes an EC2 instance, an S3 bucket, and a custom VPC. It outlines the installation of Terraform, the configuration of the EC2 instance, VPC setup with public and private subnets, and the creation of an S3 bucket, emphasizing the benefits of Infrastructure as Code (IaC). The document provides specific Terraform commands and configurations for each component, facilitating automated and consistent cloud resource management.

Uploaded by

Anil Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Integration of Terraform with

AWS to create an EC2 instance,


S3 Bucket and a Custom VPC
Setup
YAGNESH A
B.E Computer Science and Engineering
Jeppiaar Engineering College
1

Overview
This implementation document demonstrates the integration of Terraform with Amazon
Web Services (AWS) to provision a complete cloud infrastructure. The setup includes an
EC2 instance, an S3 bucket, and a custom VPC with public and private subnets.

This approach eliminates repetitive manual steps, enabling scalable, consistent, and
version-controlled infrastructure deployment. The project showcases the practical
application of Infrastructure as Code (IaC), bridging theory and real-world cloud
provisioning with Terraform and AWS.

Demonstration with Snippets


Installation of Terraform in our Linux System
1.1: Connecting EC2 instance with Amazon Linux
cd <directory of your .pem file>

ssh -i "myec2keypair.pem" ec2-user@<public-ip>


2

1.2 : Installation of the packages


Make sure you visit the official site of Terraform and search for the OS in which you are
going to install the packages and copy paste the commands in your CLI to ensure the latest
version is beig installed in your system
Since my system is Amazon Linux , These were the commands which were required for
me to install the packages
sudo yum install -y yum-utils shadow-utils
sudo yum-config-manager --add-repo
https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo
sudo yum install terraform
3
4

1.3 Set IAM role for EC2 [Administrator access] so that terraform can access our AWS
5
6
7

I have named the IAM role as Terraform-exec

Before starting with any action in Terraform, This is a mandatory step


8

PART 1 - Creating an EC2 Instance


The configurations of the instance which i have initiated is as follows

●​ Instance name : myfirstec2instance


●​ OS type : Amazon Linux
●​ Instance type : t3.micro
●​ Keypair type : RSA
●​ Private key file format : .pem
●​ VPC : default
●​ Security group : Allowed SSH traffic from anywhere 0.0.0.0/0, HTTP
AND HTTPS traffic from the internet
●​ Configure Storage : 1x8 gib,gp3

Terraform code for this configiruation is in this repository


yaggy17/Terraform-implementations

Make a directory for storing the code file into the folder using
mkdir <directory name>
Move into the created directory using cd <directory name>
Now, using the command vim <terraform filename>, insert the code written
into it and click ESC button and type :wq to quit from the write mode
Then enter the following commands
terraform init - Initializes working directory, downloads providers, sets up
Terraform.
terraform plan - Shows planned changes without applying them.
terraform apply - Executes changes to match configuration.
9
10
11
12
13

The instance is being created as per the required configuration


14

PART 2 - Configuring a VPC


The configurations of the vpc setup are as follows
VPC (Virtual Private Cloud)

●​ Name: tf-vpc
●​ CIDR Block: 10.0.0.0/16
●​ Instance Tenancy: default

Public Subnet

●​ Name: tf-ps.
●​ CIDR Block: 10.0.1.0/24
●​ Associated VPC: tf-vpc

Private Subnet

●​ Name: tf-pvts
●​ CIDR Block: 10.0.2.0/24
●​ Associated VPC: tf-vpc
15

Internet Gateway

●​ Name: tf-igw.
●​ Attached VPC: tf-vpc

Public Route Table

●​ Name: tf-pub-rt
●​ VPC ID: aws_vpc.tfvpc.id
●​ Route: 0.0.0.0/0 via the Internet Gateway
(aws_internet_gateway.gw.id)..

Private Route Table

●​ Name: tf-pvt-rt
●​ VPC ID: aws_vpc.tfvpc.id

Route Table Associations

●​ Public Subnet is associated with tf-pub-rt.


●​ Private Subnet is associated with tf-pvt-rt.

For the private subnet, NAT Gateway is mandatory to enable the internet
connection. Since it occurs charges, i havent implemented its creation.

Terraform code for this configiruation is in this repository


yaggy17/Terraform-implementations

Make a directory for storing the code file into the folder using
mkdir <directory name>
Move into the created directory using cd <directory name>
Now, using the command vim <terraform filename>, insert the code written
into it and click ESC button and type :wq to quit from the write mode
Then enter the following commands
16

terraform init - Initializes working directory, downloads providers, sets up


Terraform.
terraform plan - Shows planned changes without applying them.
terraform apply - Executes changes to match configuration.
17
18

The VPC setup is being created as per the required configuration


19
20
21

PART 3 - Creating an S3 Bucket


The configurations of the S3 bucket which we are going to create are as follows​

●​ Region : US.East(N.Virginia)
●​ Bucket type : General purpose
●​ Bucket name : my-first-s3-bucket
●​ Object ownership : ACL s Disabled [recommended]
●​ Disabled Block public access checkboxes
●​ Encryption type : Server side encryption with Amazon S3 managed
keys [SSE-S3]
●​ Bucket key : Enable

Terraform code for this configiruation is in this repository


yaggy17/Terraform-implementations

Make a directory for storing the code file into the folder using
22

mkdir <directory name>


Move into the created directory using cd <directory name>
Now, using the command vim <terraform filename>, insert the code written
into it and click ESC button and type :wq to quit from the write mode
Then enter the following commands
terraform init - Initializes working directory, downloads providers, sets up
Terraform.
terraform plan - Shows planned changes without applying them.
terraform apply - Executes changes to match configuration.
23
24

The S3 Bucket is being created as per the configuration

You might also like