WorkCloud
AWS infrastructure with Terraform
I defined in Terraform the infrastructure to move an educational web platform from Amplify and Supabase to its own architecture inside a VPC: CloudFront with WAF, an internal load balancer, ECS Fargate, private RDS and encrypted S3. Designed for data about minors and a tight budget.
- Role
- Sole author of the infrastructure. Architecture, Terraform and rollout
- Period
- Nov 2026 — Present
- Status
- In QA
- Team
- A teammate develops the web app. I own the infrastructure, the containerization and the mobile app integration
Professional project: the name and client details are anonymized. The technical description is real.
Context
A web platform that manages dual training for a school network was running on Amplify, with its database and files on Supabase. A teammate develops the application itself. I lead its migration to AWS.
In just over a week I wrote, as the sole author, the whole QA environment's infrastructure in Terraform and brought it up.
The problem
The platform needed infrastructure of its own that was reproducible and auditable. It stores data and evidence photos of underage students, so the database and the files had to stay off the internet, and the secrets out of the code.
All of it on the budget of an educational program.
What I built
10 reusable Terraform modules of my own that make up the environment: 96 resources of 52 different types in about 2,400 lines of HCL.
A three-tier network (public, application and data) where the database has no route to the internet and the public subnet only hosts the NAT.
CloudFront with WAF as the only way in: the load balancer is internal and only takes traffic from CloudFront through VPC Origins, so the WAF cannot be bypassed.
The app on ECS Fargate running ARM64, with immutable image tags in ECR, a circuit breaker with automatic rollback and a separate task for migrations.
Private RDS PostgreSQL 17: encrypted with its own KMS key, mandatory TLS, IAM authentication, backups with point-in-time recovery and deletion protection.
An S3 bucket for evidence photos whose policy denies reads and writes unless the request comes through the VPC endpoint, even with valid credentials.
Secrets kept out of the code, out of GitHub and out of the Terraform state:
SecureStringparameters whose values are loaded separately, and a master password managed by RDS.In the app, what it needed to run in containers: the multi-stage Dockerfile (standalone output, non-root user), the evidence store on S3 using the task role, verified TLS to RDS and a health endpoint.
The mobile app's serverless backend (API Gateway with a JWT authorizer and a Lambda inside the VPC), defined and ready to be switched on.
Architecture
QA environment. The database lives in subnets with no route to the internet, the evidence bucket only accepts requests that come through the VPC endpoint, and the only public entry point is CloudFront.
- Client
- Edge and network
- Managed service
- Compute
- Data
- Client:
- Browser
- Edge:
- CloudFront + WAF: VPC Origins · TLS 1.2+
- Application subnet:
- Internal ALB: CloudFront only
- Compute:
- ECR: immutable tags
- ECS Fargate: Next.js · ARM64
- Parameter Store: SecureString · KMS
- Data:
- RDS PostgreSQL 17: KMS · TLS · IAM
- S3 · evidence: VPC endpoint only
Connections:
- Browser → CloudFront + WAF
- CloudFront + WAF → Internal ALB (HTTPS)
- Internal ALB → ECS Fargate
- ECR → ECS Fargate
- ECS Fargate → Parameter Store
- ECS Fargate → RDS PostgreSQL 17
- ECS Fargate → S3 · evidence
Technical decisions
Each hop only accepts the previous one
Security groups are chained by reference rather than by IP ranges: CloudFront, load balancer, tasks and database. The Lambda can only reach the database.
Designing with cost in sight
The database, the web tier and the mobile backend each have an on/off switch (using
count), the NAT is at4g.nanoinstance instead of a NAT Gateway, and Fargate and Lambda run on ARM64. A QA environment does not have to cost what production does.A Terraform state that is hard to break
An S3 backend with native locking (
use_lockfile, no DynamoDB), in a versioned bucket withprevent_destroy, plusallowed_account_idsso nothing is applied to the wrong account.A health check that does not depend on the database
The load balancer restarts tasks based on the health check. If that check queried the database, an RDS outage would restart tasks that are perfectly healthy.
Stack
- Infrastructure as code
- Terraform
- HCL
- AWS provider
- Network and edge
- VPC
- CloudFront
- VPC Origins
- AWS WAF
- Application Load Balancer
- Route 53
- ACM
- Compute
- ECS Fargate
- ECR
- AWS Lambda
- API Gateway
- Data and secrets
- RDS PostgreSQL 17
- Amazon S3
- KMS
- Parameter Store
- Secrets Manager
- Application
- Docker
- Next.js
- Prisma
- AWS SDK v3
Outcome
QA environment up and running on the new infrastructure: network, database and the web app served from ECS Fargate.
Three first-deploy failures diagnosed and fixed: a 502 on static files, a 504 caused by a load balancer rule and an error in the migration task.
What is still missing: the production environment and a deployment pipeline. Today deploys are manual, through
terraform planandapply.
What I learned
With CloudFront VPC Origins, the load balancer's inbound rule has to reference the security group CloudFront creates in the VPC, not the VPC range.
CloudFront validates the load balancer's certificate against the forwarded
Host, so the cache behavior for static files needs the forwarding policy too.The WAF and the CloudFront certificate are created in
us-east-1, which forces a provider alias that has to be passed into the modules.Terraform's lock file pins providers but not modules: an external module's version has to be pinned exactly.
Choosing between presigned links and server-side delivery depends on how private the data is. For photos of minors, the bucket only accepts traffic from the VPC.