This project demonstrates the use of Terraform to provision and manage AWS infrastructure using Infrastructure as Code (IaC) principles.
Instead of creating resources manually through the AWS Console, all infrastructure components were defined declaratively and deployed in a repeatable, automated way. The project focuses on correctness, security, and clean lifecycle management — including safe teardown to avoid unnecessary costs.
- Use Terraform to provision AWS infrastructure
- Configure AWS provider securely using IAM (not root)
- Create an EC2 instance and security group via code
- Restrict SSH access using CIDR-based rules
- Output useful infrastructure information
- Safely destroy infrastructure after verification
- Follow Free Tier–friendly and cost-aware practices
- Terraform installed (v1.0+)
- AWS Account with programmatic access
- AWS CLI configured with IAM credentials
- EC2 Key Pair created in target region
- Basic knowledge of Terraform HCL syntax
aws configure
# Enter your AWS Access Key ID, Secret Access Key, Region, and Output formatterraform initterraform planterraform apply -var="key_name=YOUR_KEY_NAME" -var="ssh_cidr=YOUR_PUBLIC_IP/32"# Get instance public IP from outputs
terraform output instance_public_ip
# SSH into instance
ssh -i your-key.pem ubuntu@$(terraform output -raw instance_public_ip)terraform destroyflowchart TB
Dev[Developer Laptop]
TF[Terraform CLI]
AWS[AWS Account]
EC2[EC2 Instance<br/>Ubuntu 22.04]
SG[Security Group<br/>SSH + HTTP]
Dev --> TF
TF --> AWS
AWS --> EC2
AWS --> SG
SG --> EC2
- IaC Tool: Terraform
- Cloud Provider: AWS
- Compute: Amazon EC2 (t2.micro – Free Tier)
- OS: Ubuntu 22.04 LTS
- Security: AWS Security Groups, SSH key-based access
- Authentication: IAM User + AWS CLI credentials
- Ubuntu 22.04 (latest AMI)
- Free Tier eligible instance type
- SSH access via EC2 Key Pair
- Public IP assigned dynamically
- SSH (22) restricted to developer's public IP
- HTTP (80) open for web traffic
- All outbound traffic allowed
- AWS root user not used for Terraform
- Dedicated IAM user with programmatic access
- AWS credentials stored locally via
aws configure - No secrets hardcoded in Terraform files
- SSH access restricted by CIDR
- Infrastructure destroyed after validation
project-06-terraform-aws/
├── main.tf
├── provider.tf
├── variables.tf
├── outputs.tf
├── README.md
├── .gitignore
└── architecture/
└── terraform-aws-ec2.mmd
- ✅ Initialized Terraform (
terraform init) - ✅ Reviewed execution plan (
terraform plan) - ✅ Applied infrastructure (
terraform apply) - ✅ Connected to EC2 via SSH successfully
- ✅ Verified networking and security behavior
- ✅ Destroyed all resources (
terraform destroy)
After successful validation, all AWS resources were destroyed using:
terraform destroyThis ensures:
- No ongoing AWS costs
- No orphaned resources
- Clean and repeatable infrastructure lifecycle
- Provisioned AWS infrastructure using Terraform (IaC)
- Automated EC2 and security group creation via code
- Implemented secure IAM-based authentication
- Debugged real-world SSH and networking issues
- Practiced full infrastructure lifecycle management
Terraform · AWS · EC2 · Infrastructure as Code · DevOps · Cloud Engineering