Code was written and tested with the following (these versions are enforced in code as minimums):
- OpenTofu v1.6.2
- Terragrunt 0.55.15
- hashicorp/aws v5.46.0
- hashicorp/random v3.6.1
Note: All code should be run through Terragrunt, which will then execute the required Tofu commands
Contains the remote state resources:
- S3 bucket - state
- DynamoDB - locks
Contains the VPC and all core network resources and supporting security groups etc...including:
- subnets
- vpc endpoints
- IGW
- NAT gateways
Contains the ECS cluster & Application Load Balancer for the backend & supporting resources
- ECS cluster
- application load balancer
- security group
Contains the Elasticache redis cluster and supporting resources
- Elasticache serverless Redis cache
- security group
Contains the RDS database instance and supporting resources
- RDS mysql database
- security group
Contains the Cloudfront CDN distribution, frontend S3 bucket and supporting resources. WHile the bucket contents will change with frontend code changes the infrastructure defined here will remain static
- S3 bucket
- Cloudfront distribution
- Cloudfront function
Contains the backend ECS service and task definitions. This will be redeployed whenever the backend code is updated
- ECS service
- ECS task definition
All infrastructure should be deployed via terragrunt commands from the appropriate 'environments' folder. Tofu should never be executed directly from the 'modules' folders
This is deployed individually before any other stacks and generally should not change with application or infrastructure deployments. For the initial run in a new environment comment out the "generate "backend" block in tofu/environments/terragrunt.hcl. This is required to created the backend S3 state bucket and DynamoDB lock table.
- tofu/environments/<env>/terraform/tfbackend
cd tofu/environments/<env>/terraform/tfbackendterragrunt initterragrunt validateterragrunt plan -out tfplanterragrunt apply tfplan
These should be deployed in the following order and generally will only be updated with infrastructure changes while remaining static for code changes. The Tofu files pull some information from environment variables. When Github Actions workflows are run these are populated by Github environment/repository variables. When running terragrunt commands locally the specified environment variables must be set/
-
tofu/environments/<env>/network/vpc Required Environment Variables:
- TF_VAR_name_prefix
- TF_VAR_environment
- TF_VAR_region
cd tofu/environments/<env>/network/vpcterragrunt initterragrunt validateterragrunt plan -out tfplanterragrunt apply tfplan
-
tofu/environments/<env>/services/backend-infra Required Environment Variables:
- TF_VAR_name_prefix
- TF_VAR_environment
- TF_VAR_region
- TF_VAR_frontend_url
cd tofu/environments/<env>/services/backend-infraterragrunt initterragrunt validateterragrunt plan -out tfplanterragrunt apply tfplan
-
tofu/environments/<env>/data-store/cache Required Environment Variables:
- TF_VAR_name_prefix
- TF_VAR_environment
- TF_VAR_region
cd tofu/environments/<env>/datastore/cacheterragrunt initterragrunt validateterragrunt plan -out tfplanterragrunt apply tfplan
-
tofu/environments/<env>/data-store/database Required Environment Variables:
- TF_VAR_name_prefix
- TF_VAR_environment
- TF_VAR_region
cd tofu/environments/<env>/data-store/databaseterragrunt initterragrunt validateterragrunt plan -out tfplanterragrunt apply tfplan
-
tofu/environments/<end>/services/frontend-infra Required Environment Variables:
- TF_VAR_name_prefix
- TF_VAR_environment
- TF_VAR_region
cd tofu/environments/<env>/services/frontend-infraterragrunt initterragrunt validateterragrunt plan -out tfplanterragrunt apply tfplan
The application backend is deployed as an ECS service via terragrunt
-
tofu/environments/<env>/services/backend-service Required Environment Variables:
- TF_VAR_name_prefix
- TF_VAR_environment
- TF_VAR_region
- TF_VAR_name_frontend_url
- TF_VAR_short_base_url
- TF_VAR_app_env
- TF_VAR_sentry_dsn
- TF_VAR_zoom_callback
- TF_VAR_db_enc_secret
- TF_VAR_smtp_secret
- TF_VAR_google_oauth_secret
- TF_VAR_zoom_secret
- TF_VAR_fxa_secret
- TF_VAR_log_level
cd tofu/environments/<env>/services/backend-serviceterragrunt initterragrunt validateterragrunt plan -out tfplanterragrunt apply tfplan
The application frontend is deployed to an S3 bucket fronted by Cloudfront. As such it can be deployed by uploadingx files to S3 and creating a Cloudfront invalidation.
- aws s3 sync frontend/dist <Appointment Environment Frontend S3 Bucket URI>
- aws cloudfront create-invalidation --distribution-id <Appointment Environment Cloudfront Distribution ID> --paths "/*"