Skip to content

Commit cf2d4f9

Browse files
Create configuration for data replication
- This produces a replicate DB with a single ECS task connected - Usefull for testing migrations/sql/etc on a production data without actually modifying the production system - The replicate DB will be spawned from a snapshot which is passed as a variable - Some modification was done to the ecs module to ensure that task definitions are distinct
1 parent 3f6e39d commit cf2d4f9

22 files changed

Lines changed: 418 additions & 2 deletions

.github/workflows/deploy-data-replica.yml

Whitespace-only changes.

terraform/app/modules/ecs_service/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ resource "aws_security_group_rule" "egress_all" {
2727
}
2828

2929
resource "aws_ecs_service" "this" {
30-
name = "mavis-${var.environment}-${var.server_type}"
30+
name = "${var.naming_prefix}${var.environment}-${var.server_type}"
3131
cluster = var.cluster_id
3232
task_definition = aws_ecs_task_definition.this.arn
3333
desired_count = var.minimum_replica_count
@@ -70,7 +70,7 @@ resource "aws_ecs_service" "this" {
7070
}
7171

7272
resource "aws_ecs_task_definition" "this" {
73-
family = "mavis-${var.server_type}-task-definition-${var.environment}"
73+
family = "${var.naming_prefix}${var.server_type}-task-definition-${var.environment}"
7474
requires_compatibilities = ["FARGATE"]
7575
network_mode = "awsvpc"
7676
cpu = var.task_config.cpu

terraform/app/modules/ecs_service/variables.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ variable "maximum_replica_count" {
2626
}
2727
}
2828

29+
variable "naming_prefix" {
30+
type = string
31+
description = "Prefix to be used for naming the ECS service and task definition"
32+
default = "mavis-"
33+
nullable = false
34+
}
35+
2936
variable "autoscaling_policies" {
3037
type = map(object({
3138
predefined_metric_type = string

terraform/data_replication/ecs.tf

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
resource "aws_ecs_cluster" "cluster" {
3+
name = local.name_prefix
4+
5+
setting {
6+
name = "containerInsights"
7+
value = "enabled"
8+
}
9+
}
10+
11+
resource "aws_cloudwatch_log_group" "ecs_log_group" {
12+
name = "${local.name_prefix}-ecs"
13+
retention_in_days = 1
14+
skip_destroy = false
15+
}
16+
17+
18+
module "db_access_service" {
19+
source = "../app/modules/ecs_service"
20+
cluster_id = aws_ecs_cluster.cluster.id
21+
cluster_name = aws_ecs_cluster.cluster.name
22+
environment = var.environment
23+
naming_prefix = "mavis-data-replication-"
24+
maximum_replica_count = 1
25+
minimum_replica_count = 1
26+
network_params = {
27+
subnets = local.subnet_list
28+
vpc_id = aws_vpc.vpc.id
29+
}
30+
server_type = "good-job"
31+
task_config = {
32+
environment = local.task_envs
33+
secrets = local.task_secrets
34+
cpu = 1024
35+
memory = 2048
36+
docker_image = "${var.account_id}.dkr.ecr.eu-west-2.amazonaws.com/${var.docker_image}@${var.image_digest}"
37+
execution_role_arn = aws_iam_role.ecs_task_execution_role.arn
38+
task_role_arn = aws_iam_role.ecs_task_role.arn
39+
log_group_name = aws_cloudwatch_log_group.ecs_log_group.name
40+
region = var.region
41+
health_check_command = ["CMD-SHELL", "curl -f http://localhost:4000 || exit 1"]
42+
}
43+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
bucket = "nhse-mavis-terraform-state-production"
2+
key = "terraform-data-replication-production.tfstate"
3+
region = "eu-west-2"
4+
dynamodb_table = "mavis-terraform-state-lock"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
environment = "production"
2+
rails_env = "production"
3+
rails_master_key_path = "/copilot/mavis/production/secrets/RAILS_MASTER_KEY"
4+
max_aurora_capacity_units = 16
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
bucket = "nhse-mavis-terraform-state"
2+
key = "terraform-data-replication-qa.tfstate"
3+
region = "eu-west-2"
4+
dynamodb_table = "mavis-terraform-state-lock"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
environment = "qa"
2+
rails_master_key_path = "/copilot/mavis/secrets/STAGING_RAILS_MASTER_KEY"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
bucket = "nhse-mavis-terraform-state"
2+
key = "terraform-data-replication-sandbox-alpha.tfstate"
3+
region = "eu-west-2"
4+
dynamodb_table = "mavis-terraform-state-lock"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
environment = "sandbox-alpha"
2+
rails_master_key_path = "/copilot/mavis/secrets/STAGING_RAILS_MASTER_KEY"

0 commit comments

Comments
 (0)