How nationalarchives/ds-infrastructure-web works
Purpose and scope
This is AWS infrastructure-as-code for www.nationalarchives.gov.uk and its supporting web applications. Terraform manages web-platform resources; the VPC and general database infrastructure are explicitly owned elsewhere. The repository also defines EC2/AMI provisioning and GitHub Actions deployment automation.
Operational entry points
Primary infrastructure execution paths are Terraform workflows and wrapper scripts: .github/workflows/terraform-plan.yml, .github/workflows/terraform-apply.yml, and components/scripts/terraform.sh. Environment-specific deployment workflows route changes to develop, staging, or production: .github/workflows/deploy-develop.yml, .github/workflows/deploy-staging.yml, .github/workflows/deploy-production.yml.
Terraform composition and environments
components/terraform/ is the root infrastructure composition layer: top-level .tf files assemble reusable service modules for networking-adjacent web resources, identity, delivery, storage, and compute. Environment values are separated into dev, staging, and live variable/backend sets, e.g. components/terraform/_vars/dev/backend.tf, components/terraform/_vars/staging/environment.auto.tfvars, and components/terraform/_vars/live/global.auto.tfvars. This boundary allows a common topology with environment-specific capacity, names, and service settings.
Web workload fleet
Each web application has a dedicated Terraform module defining an EC2 launch template, Auto Scaling Group, and load-balancer target group. Representative modules are components/terraform/web-frontend/launch-template.tf, components/terraform/web-frontend/auto-scaling-group.tf, and components/terraform/web-frontend/target-group.tf; equivalent modules exist for catalogue, forms, search, Wagtail, and other named services. Instances bootstrap from user-data/startup scripts and receive constrained IAM/S3/SSM permissions via module templates.
Request delivery and edge security
Internet traffic is handled through CloudFront, load balancers, a reverse-proxy workload, Route 53, and AWS WAF. Key boundaries are components/terraform/cloudfront/cloudfront.tf, components/terraform/load-balancer/lb.tf, and components/terraform/web-reverse-proxy/load-balancer.tf. WAF composes custom and AWS-managed rules, including rate limiting and known-IP controls, from components/terraform/waf/waf.tf, components/terraform/waf-rule-groups/web-rate-limiting/main.tf, and components/terraform/waf-rules/aws-managed/BotControlRuleSet/main.tf.
Stateful and asynchronous services
The platform provisions Redis as an EC2 autoscaled service, EFS-backed media storage, PostgreSQL source/replica resources, SES, Cognito, and Lambda/EventBridge automation. Core paths include components/terraform/redis/auto-scaling-group.tf, components/terraform/media-efs/efs.tf, and components/terraform/postgres/replica_instance.tf. Event-driven processing includes submitted-file handling and scheduled application triggers in components/terraform/lambda/process-submitted-files/source/process-submitted-files.py, components/terraform/lambda/wagtail-cron-trigger/source/wagtail-cron-trigger.py, and components/terraform/eventbridge/main.tf.
Build, provisioning, and deployment flow
Per-application AMI workflows build machine images, then Ansible configures Docker/Traefik-hosted workloads and blue-green deployment scripts. Examples are .github/workflows/web-wagtail-ami-build.yml, .github/ansible-playbooks/wagtail/web-wagtail-playbook.yml, and .github/ansible-playbooks/wagtail/files/website-blue-green-deploy.sh. GitHub composite actions centralize runtime setup, Terraform planning, deployment, and environment-variable updates: .github/actions/setup-runtime/action.yml, .github/actions/terraform-plan/action.yml, and .github/actions/deploy/action.yml. Runtime configuration is supplied per application and environment under config/parameters/, such as config/parameters/wagtail/production.json.
Main entry points: terraform Platform composition · auto-scaling-group.tf Web application fleets · deploy-production.yml Environment deploy workflows · cloudfront.tf CloudFront and WAF
Components 19
CI/CD automation
- Environment deploy workflows · Routes deployments to develop, staging, and production.
.github/workflows/deploy-production.yml - Terraform plan and apply
.github/workflows/terraform-plan.yml - Terraform wrapper
components/scripts/terraform.sh - Shared CI actions · Sets up runtime and standardizes planning and deployment.
.github/actions/terraform-plan/action.yml - AMI build and provisioning · Builds application images and configures Docker/Traefik workloads.
.github/workflows/web-wagtail-ami-build.yml - Runtime parameters
config/parameters/wagtail/production.json
Terraform platform
- Platform composition · Assembles reusable web-platform infrastructure modules.
components/terraform - Environment variables and backends · Dev, staging, and live settings select shared topology variants.
components/terraform/_vars/dev/backend.tf
Request delivery
- CloudFront and WAF · Applies CDN delivery, managed/custom rules, rate limits, and IP controls.
components/terraform/cloudfront/cloudfront.tf - Route 53
- Load balancer
components/terraform/load-balancer/lb.tf - Reverse-proxy fleet · Routes load-balancer traffic to application services.
components/terraform/web-reverse-proxy/load-balancer.tf
Application workloads
- Web application fleets · Dedicated launch template, ASG, and target group per application.
components/terraform/web-frontend/auto-scaling-group.tf - IAM, S3, and SSM access · Constrained instance access is attached through module templates.
State and events
- Redis fleet
components/terraform/redis/auto-scaling-group.tf - Media EFS
components/terraform/media-efs/efs.tf - PostgreSQL replica resources · Database infrastructure is generally owned outside this repository.
components/terraform/postgres/replica_instance.tf - Lambda and EventBridge · Processes submitted files and invokes scheduled application tasks.
components/terraform/eventbridge/main.tf - Cognito and SES
Connections 26
- Environment deploy workflows → Shared CI actions: uses
- Environment deploy workflows → AMI build and provisioning: builds images
- Environment deploy workflows → Runtime parameters: loads
- Terraform plan and apply → Shared CI actions: uses
- Terraform plan and apply → Terraform wrapper: runs
- Terraform wrapper → Platform composition: applies
- Platform composition → Environment variables and backends: selects
- Platform composition → CloudFront and WAF: provisions
- Platform composition → Load balancer: provisions
- Platform composition → Web application fleets: provisions
- Platform composition → Redis fleet: provisions
- Platform composition → Media EFS: provisions
- Platform composition → PostgreSQL replica resources: manages replica resources
- Platform composition → Lambda and EventBridge: provisions
- Platform composition → Cognito and SES: provisions
- Route 53 → CloudFront and WAF: resolves to
- CloudFront and WAF → Load balancer: forwards requests
- Load balancer → Reverse-proxy fleet: targets
- Reverse-proxy fleet → Web application fleets: routes to
- AMI build and provisioning → Web application fleets: publishes AMIs for
- Web application fleets → IAM, S3, and SSM access: receives
- Web application fleets → Redis fleet: uses
- Web application fleets → Media EFS: mounts
- Web application fleets → PostgreSQL replica resources: connects to
- Web application fleets → Cognito and SES: uses
- Lambda and EventBridge → Web application fleets: triggers scheduled tasks