Skip to content

About

Reusable Ramin starter application infra

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Ramin Starter Infrastructure

Generic Terraform infrastructure for the Ramin NestJS and React starter application.

Architecture

  • CloudFront serves a private S3 frontend and proxies /api/* to an ALB.
  • A CloudFront Function handles SPA routes without rewriting API errors.
  • The ALB accepts only CloudFront origin-facing addresses and requires a generated origin header.
  • ECS Fargate tasks run in two private subnets and reach external services through one NAT gateway.
  • Cognito provides authorization-code-with-PKCE authentication for the SPA.
  • Secrets Manager stores the MongoDB URI; Terraform creates only the empty secret container.
  • A second private S3 bucket supports application file storage.
  • Optional Route 53, ALB, ECS, CloudWatch, and SNS monitoring is disabled by default.

The single NAT gateway is a deliberate starter-cost choice and is not Availability Zone redundant. Production applications can move to one NAT gateway per Availability Zone when that availability/cost tradeoff is justified. Non-current frontend object versions expire after 30 days; uniquely named immutable assets remain available so an older browser shell never points at a deleted deployment asset.

Local Setup

Requirements: Terraform 1.7 or newer and AWS credentials only when running plan or apply.

scripts/setup-local.sh
scripts/verify.sh

scripts/verify.sh formats, initializes without a backend, validates, and runs mocked-provider Terraform tests. It does not contact or modify AWS.

State

Local state is the default onboarding mode and is ignored by Git. For shared or production work:

  1. Create an S3 state bucket outside this stack with encryption, versioning, public access blocking, and restricted IAM access.
  2. Copy backend.tf.example to ignored backend.tf.
  3. Copy backend.hcl.example to ignored backend.hcl and set the bucket, key, and region.
  4. Run terraform init -reconfigure -backend-config=backend.hcl.

The S3 backend example uses native lockfiles. State is sensitive because it contains the generated CloudFront-to-ALB verification value. Do not commit state, plans, real tfvars, or backend configuration.

First Deployment

  1. Set project, environment, owner, and exact GitHub repository values in terraform.tfvars.
  2. If GitHub's OIDC provider already exists in the AWS account, set github_oidc_provider_arn. Only one provider with that URL can exist per account.
  3. Run scripts/verify.sh, then review terraform plan.
  4. Apply the stack only after approval. The ECS service starts at zero tasks, so the placeholder image is never pulled.
  5. Put the MongoDB URI into the output secret outside Terraform. Never pass it through a Terraform variable.
  6. Copy github_backend_repository_variables and github_frontend_repository_variables into their matching GitHub repositories or environments.
  7. Manually run the backend deployment, then the frontend deployment.

The deployment workflows own the live ECS task-definition revision and desired count. Terraform intentionally ignores those two ECS service fields after bootstrap so a later infrastructure apply cannot roll an application release backward or scale it to zero. Terraform still owns the task-definition baseline, IAM, networking, environment variables, and secret references; backend deployments inherit the latest baseline and replace only its image.

Monitoring

Set monitoring_enabled = true to create endpoint health checks, ALB/ECS alarms, and SNS email subscriptions. Confirm each SNS subscription email before expecting alerts. When the application region is not us-east-1, Route 53 health-check alarms and their SNS topic live in us-east-1; regional ALB/ECS alarms use a regional topic. Monitoring, NAT, ALB, and other resources incur recurring AWS charges.

Destruction

Buckets retain data by default and can block terraform destroy. Empty them deliberately first. Setting allow_destroy_nonempty_buckets = true is an explicit destructive opt-in and should not be a routine production setting. Secrets use a seven-day recovery window.

Custom domains, ACM, Route 53 hosted zones, WAF, MongoDB Atlas provisioning, Bedrock, autoscaling, and Terraform apply workflows are intentionally outside this starter stack.

About

Reusable Ramin starter application infra

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages