Terraform
Terraform
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.
1.3 Set IAM role for EC2 [Administrator access] so that terraform can access our AWS
5
6
7
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
● 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
● 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)..
● Name: tf-pvt-rt
● VPC ID: aws_vpc.tfvpc.id
For the private subnet, NAT Gateway is mandatory to enable the internet
connection. Since it occurs charges, i havent implemented its creation.
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
● 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
Make a directory for storing the code file into the folder using
22