This project demonstrates a real-world continuous deployment setup using GitHub Actions, Terraform, and EC2 for a simple FastAPI backend. It covers two environments: staging (auto-deployed) and production (manual approval).
.
├── .github/
│ └── workflows/
│ ├── deploy_staging.yml
│ └── deploy_production.yml
├── app/
│ ├── __init__.py
│ └── main.py
├── terraform/
│ ├── ec2.tf
│ ├── ecr.tf
│ ├── iam.tf
│ ├── outputs.tf
│ ├── provider.tf
│ ├── variables.tf
│ └── .terraform.lock.hcl
├── Dockerfile
├── requirements.txt
└── README.md
- GitHub Actions CI/CD pipeline for two environments
- Secure environment variables using GitHub secrets
- Docker image build and push to AWS ECR
- Terraform-managed EC2 and IAM setup
- Dynamic environment injection (staging/production)
- Clean production deployment triggered manually
// Staging
{"env": "staging", "version": "1", "status": "running"}
// Production
{"env": "production", "version": "1", "status": "running"}
- Configure AWS credentials and backend.
- Run
terraform init
&terraform apply
from theterraform/
directory.
In your GitHub repository settings, add these secrets:
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
ECR_REPOSITORY
EC2_STAGING_IP
EC2_PROD_IP
- On push to
main
: auto-deploys to staging. - From GitHub UI: trigger manual production deployment when staging looks good.
Not just a random demo — this was built step by step with real hands-on effort, debugging weird issues and setting things up like you would in a real team. If it helps you or you want to tweak it for your own setup, go ahead. PRs always welcome.