Skip to content

Repository files navigation

🛒 Shopshere Terraform Infrastructure

This project provisions a production-grade AWS infrastructure using Terraform with a modular and scalable architecture.


🚀 What We Built (Start → End)

We built this infrastructure step-by-step like a real DevOps workflow:

1️⃣ VPC (Networking Foundation)

  • Created a custom VPC
  • Public and Private subnets across multiple AZs
  • Internet Gateway for public access
  • Route tables for proper traffic routing

2️⃣ Security Groups (Layered Security)

  • Separate security groups for:

    • ALB
    • EC2
  • Implemented:

    • SSH restricted to developer IP
    • HTTP open only where required
    • EC2 accepts traffic only from ALB

3️⃣ EC2 (Application Layer)

  • Launched EC2 instance using Terraform
  • Installed Nginx using user_data
  • Configured SSH access with key pair
  • Output public IP for testing

4️⃣ ALB (Load Balancer)

  • Application Load Balancer in public subnets
  • Target Group with health checks
  • Listener routing HTTP → EC2
  • Attached EC2 instance to ALB

5️⃣ Production Security Hardening 🔐

  • Removed public access from EC2

  • Introduced ALB as the only entry point

  • Implemented SG-to-SG communication:

    • ALB → EC2 only

6️⃣ NAT Gateway (Private Internet Access)

  • Added Elastic IP + NAT Gateway
  • Enabled private EC2 instances to access internet
  • Fixed issue where Nginx install failed without internet

🧠 Key Learnings

🔥 Terraform Concepts

  • Modules should NOT be applied individually
  • Use environment folders (dev, prod) for execution
  • Use outputs to expose module data
  • Use ${path.module} for file references

🔥 AWS Networking

  • Public subnet = Internet Gateway route
  • Private subnet = NAT Gateway route
  • No NAT = no outbound internet

🔥 Debugging Skills

  • 502 Bad Gateway → backend issue
  • Target Group unhealthy → app not responding
  • SG dependency errors → resource still attached
  • Key pair issues → must recreate EC2

🏗️ Final Architecture

Internet
   ↓
ALB (Public Subnet)
   ↓
EC2 (Private Subnet)
   ↓
NAT Gateway → Internet

📁 Project Structure

shopshere-terraform/

├── modules/
│   ├── vpc/
│   ├── ec2/
│   ├── alb/
│   ├── security_group/
│
├── environments/
│   ├── dev/
│   ├── prod/
│
├── global/
│   ├── s3-backend/
│
├── provider.tf
├── variables.tf
├── outputs.tf
├── versions.tf

⚙️ How to Use

1. Navigate to environment

cd environments/dev

2. Initialize Terraform

terraform init

3. Plan

terraform plan

4. Apply

terraform apply

🧪 Testing

  • Access app via:
http://<ALB_DNS>
  • EC2 is NOT publicly accessible (by design)

⚠️ Important Notes

  • NAT Gateway incurs cost 💸
  • Do NOT expose EC2 publicly in production
  • Always restrict SSH access
  • Never hardcode secrets in Terraform

🔐 Future Improvements

  • Use AWS SSM Session Manager instead of SSH
  • Add Auto Scaling Group
  • Add HTTPS (ACM + Route53)
  • Store secrets in AWS Secrets Manager
  • CI/CD integration (GitHub Actions)

🏁 Conclusion

This project demonstrates a real-world production-ready AWS architecture using Terraform:

✔ Modular ✔ Secure ✔ Scalable ✔ Maintainable


💡 Built as a hands-on DevOps learning project

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages