I built this project to move away from "Click-Ops" (manually clicking around the AWS Console) and fully embrace Infrastructure as Code (IaC).
In this repository, I’ve shared my Terraform scripts that automatically set up a secure, custom VPC and launch a Linux EC2 instance. My main goal was to ensure that the entire networking stack—from subnets to routing—is repeatable and follows security best practices. I also focused heavily on security by ensuring sensitive files like state files and private keys are never exposed to version control.
- Infrastructure as Code: Terraform (HCL)
- Cloud Provider: Amazon Web Services (AWS)
- Networking: VPC, Public Subnet, Internet Gateway (IGW), Route Tables
- Compute: EC2 (Amazon Linux 2)
- Security: Security Groups (SSH & HTTP access), SSH Key Pairs
- Version Control: Git & GitHub
- Custom VPC Architecture: Created a dedicated Virtual Private Cloud (VPC) to ensure the infrastructure is isolated and secure, rather than using the default AWS settings.
- Automated Networking: Configures the Public Subnet, Internet Gateway (IGW), and Route Tables automatically to provide the EC2 instance with internet connectivity.
- Security Group Rules: Implemented a restricted Security Group that only allows SSH (Port 22) for management and HTTP (Port 80) for web traffic.
- Optimized Storage: Provisions the EC2 instance with gp3 EBS volumes, providing better performance and cost-efficiency than the standard gp2.
- Safe State Management: Utilizes a professional
.gitignoreconfiguration to ensure that sensitive files liketerraform.tfstateand private keys never leave the local environment.
Follow these steps to deploy this infrastructure in your own AWS account:
- AWS CLI configured with your credentials.
- Terraform installed on your local machine.
- SSH Key Pair: Create a key pair directly in your project root folder using the command below. You can replace
"my-key"with any name you prefer:ssh-keygen -f "my-key"
Download the necessary AWS providers and set up the working directory.
terraform initPreview the resources Terraform will create. This is a crucial step to verify your configuration before deployment.
terraform planDeploy the VPC, Networking, and EC2 instance to your AWS account.
terraform apply -auto-approveOnce the process is complete, Terraform will display the Public IP. Use your private key to SSH into the instance:
ssh -i "your-key-name" ec2-user@<your-public-ip>terraform destroyOnce the deployment is successful, you can verify and interact with your new infrastructure in the following ways:
After running terraform apply, you will see the following resources created in your AWS account:
- A VPC named "Custom-VPC" (or your specified name).
- A running EC2 instance with the tag "Terraform-Instance".
- A Security Group allowing traffic on ports 22 and 80.
Use the public IP address provided in the Terraform output to connect to your instance:
# Example command
ssh -i "my-key" ec2-user@3.84.123.45The project is configured to automatically display important information. You will see an output similar to this in your terminal:
Outputs:
ec2_public_ip = "3.84.123.45"
vpc_id = "vpc-0a1b2c3d4e5f6g7h8"
Once logged in, you can verify internet connectivity by pinging an external site or checking the instance metadata:
ping google.comVisual confirmation of the infrastructure deployment:
The successful output of the terraform apply command showing resources created.

Confirmation of the instance running in the AWS Console with the specified configuration.

View of the custom VPC and Subnets successfully provisioned by the script.

Nishika Jaiswal
Aspiring Cloud & DevOps Engineer