How moorthy-m/static-site-cicd-terraform works
What this project is (type + purpose)
This is a production-style static website deployment project on AWS with Infrastructure as Code + CI/CD as the primary deliverable.
• “Application”: a Vite/React static site under /site that builds to static assets.
• “Platform/Infra”: Terraform modules split into:
• Bootstrap layer (/bootstrap): IAM + GitHub OIDC trust + least-privilege roles/policies so GitHub Actions can deploy without long-lived credentials.
• Application layer (/infra): private S3 bucket + CloudFront distribution with OAC + permissions for cache invalidation.
CI/CD (GitHub Actions)
.github/workflows/
• terraform-bootstrap-ci.yml / terraform-bootstrap-cd.yml
• terraform-ci.yml / terraform-cd.yml
• terraform-site-ci.yml / terraform-site-cd.yml
This strongly suggests three pipelines/domains:
Terraform layers
• /bootstrap/*.tf: providers, variables, IAM/OIDC
• /infra/*.tf: main resources, outputs, vars (prod-infra.auto.tfvars indicates an environment)
As two Terraform stacks with explicit dependency:
• Bootstrap must exist first to allow GitHub Actions auth.
• App infra depends on bootstrap-provisioned IAM (roles/policies) and then provisions runtime resources.
Static site
• /site: Vite/React app (pages/components/data)
• site/src/utils/api.js likely just local helper; no backend indicated.
Site as a build artifact (HTML/CSS/JS) deployed to S3, served via CloudFront.
• S3 bucket is private (no public ACLs/policies)
• CloudFront uses OAC (Origin Access Control) to fetch from S3
• GitHub Actions uses OIDC to assume roles (no long-lived keys)
• Cache invalidation happens on deployment (CD step)
• No ACM/custom domain (so HTTPS details can be omitted or noted as “default CloudFront domain”)
PR triggers CI (no deploy)
• GitHub PR → Actions CI (site build validation; terraform fmt/validate/plan depending on workflow intent)
Merge to main triggers CD
• Actions → (OIDC) → AWS STS AssumeRole → IAM Role credentials
• Terraform Apply:
• Bootstrap pipeline provisions IAM/OIDC trust.
• Infra pipeline provisions S3 + CloudFront + OAC + needed permissions.
• Site pipeline:
• Build Vite app → artifacts
• Upload artifacts → S3 (PutObject)
• Create invalidation → CloudFront (InvalidateObject/paths)
OIDC as a distinct step:
• GitHub Actions → “AWS STS AssumeRoleWithWebIdentity” → IAM Role
User request flow
• Browser → CloudFront Distribution (GET /)
• CloudFront → S3 Origin (via OAC signed request)
• S3 returns objects to CloudFront → Browser
blocked path (important security invariant):
• Browser → S3 bucket (direct) = denied (private bucket, no public access)
Architectural patterns/principles used
• Layered Terraform stacks: bootstrap vs application (separation of concerns)
• Least privilege IAM: separate deploy role, restricted permissions
• Private origin: S3 not public, only accessible through CloudFront OAC
• Immutable-ish deployment: build artifacts uploaded, CDN invalidated
• Credentialless CI/CD: OIDC federation rather than static keys
Relevant technologies
• Terraform (bootstrap/app layers)
• GitHub Actions (CI/CD)
• AWS: S3, CloudFront, IAM, STS, OIDC
• Vite/React build (static assets)
Don’t overthink: “separate into as many components as possible”
For maximum accuracy/detail, prefer *explicit nodes* even if they’re small:
• Separate “OIDC Provider” from “IAM Role” from “STS”
• Separate “Build artifact” from “S3 bucket”
• Separate “Terraform Plan/Apply” from “Site Upload/Invalidate”
• Separate bootstrap Terraform from app Terraform