Skip to content

Commit

Permalink
Merge pull request #7881 from ministryofjustice/DBA-766
Browse files Browse the repository at this point in the history
Dba 766
  • Loading branch information
bill-buchan authored Sep 20, 2024
2 parents 0ace172 + ab8cf6d commit ca6e01d
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 22 deletions.
1 change: 1 addition & 0 deletions terraform/environments/delius-core/locals_development.tf
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,6 @@ locals {
user_target_endpoint = {
write_database = "DMDNDA"
}
is-production = local.is-production
}
}
1 change: 1 addition & 0 deletions terraform/environments/delius-core/locals_preproduction.tf
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ locals {
user_target_endpoint = {
write_database = "PRENDA"
}
is-production = local.is-production
}

}
1 change: 1 addition & 0 deletions terraform/environments/delius-core/locals_stage.tf
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,6 @@ locals {
user_target_endpoint = {
write_database = "STGNDA"
}
is-production = local.is-production
}
}
1 change: 1 addition & 0 deletions terraform/environments/delius-core/locals_test.tf
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,6 @@ locals {
read_database = "TSTNDA"
}
user_target_endpoint = {}
is-production = local.is-production
}
}
9 changes: 5 additions & 4 deletions terraform/environments/delius-core/main_development.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ module "environment_dev" {
count = local.is-development ? 1 : 0

providers = {
aws = aws
aws.bucket-replication = aws
aws.core-vpc = aws.core-vpc
aws.core-network-services = aws.core-network-services
aws = aws
aws.bucket-replication = aws
aws.core-vpc = aws.core-vpc
aws.core-network-services = aws.core-network-services
aws.modernisation-platform = aws.modernisation-platform
}

env_name = "dev"
Expand Down
18 changes: 10 additions & 8 deletions terraform/environments/delius-core/main_preproduction.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ module "environment_stage" {
count = local.is-preproduction ? 1 : 0

providers = {
aws = aws
aws.bucket-replication = aws
aws.core-vpc = aws.core-vpc
aws.core-network-services = aws.core-network-services
aws = aws
aws.bucket-replication = aws
aws.core-vpc = aws.core-vpc
aws.core-network-services = aws.core-network-services
aws.modernisation-platform = aws.modernisation-platform
}

env_name = "stage"
Expand Down Expand Up @@ -47,10 +48,11 @@ module "environment_preprod" {
count = local.is-preproduction ? 1 : 0

providers = {
aws = aws
aws.bucket-replication = aws
aws.core-vpc = aws.core-vpc
aws.core-network-services = aws.core-network-services
aws = aws
aws.bucket-replication = aws
aws.core-vpc = aws.core-vpc
aws.core-network-services = aws.core-network-services
aws.modernisation-platform = aws.modernisation-platform
}

env_name = "preprod"
Expand Down
9 changes: 5 additions & 4 deletions terraform/environments/delius-core/main_test.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ module "environment_test" {
count = local.is-test ? 1 : 0

providers = {
aws = aws
aws.bucket-replication = aws
aws.core-vpc = aws.core-vpc
aws.core-network-services = aws.core-network-services
aws = aws
aws.bucket-replication = aws
aws.core-vpc = aws.core-vpc
aws.core-network-services = aws.core-network-services
aws.modernisation-platform = aws.modernisation-platform
}

env_name = "test"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# SNS topic for monitoring to send alarms to
resource "aws_sns_topic" "dms_alerting" {
name = "delius-dms-alerting"
kms_master_key_id = var.account_config.kms_keys.general_shared
}

locals {
aws_dms_replication_tasks = merge(
try(var.dms_config.user_target_endpoint.write_database, null) == null ? {} : {
(aws_dms_replication_task.user_inbound_replication[0].replication_task_arn) = aws_dms_replication_task.user_inbound_replication[0].replication_task_id
},
{for k in keys(local.client_account_map) :
(aws_dms_replication_task.business_interaction_inbound_replication[k].replication_task_arn) => aws_dms_replication_task.business_interaction_inbound_replication[k].replication_task_id
},
{for k in keys(local.client_account_map) :
(aws_dms_replication_task.audited_interaction_inbound_replication[k].replication_task_arn) => aws_dms_replication_task.audited_interaction_inbound_replication[k].replication_task_id
},
{for k in keys(local.client_account_map) :
(aws_dms_replication_task.audited_interaction_checksum_inbound_replication[k].replication_task_arn) => aws_dms_replication_task.audited_interaction_checksum_inbound_replication[k].replication_task_id
},
try(var.dms_config.audit_source_endpoint.read_database, null) == null ? {} : {
(aws_dms_replication_task.audited_interaction_outbound_replication[0].replication_task_arn) = aws_dms_replication_task.audited_interaction_outbound_replication[0].replication_task_id
},
{for k in keys(local.client_account_map) :
(aws_dms_replication_task.user_outbound_replication[k].replication_task_arn) => aws_dms_replication_task.user_outbound_replication[k].replication_task_id
},
try(var.dms_config.audit_source_endpoint.read_database, null) == null ? {} : {
(aws_dms_replication_task.business_interaction_outbound_replication[0].replication_task_arn) = aws_dms_replication_task.business_interaction_outbound_replication[0].replication_task_id
},
try(var.dms_config.audit_source_endpoint.read_database, null) == null ? {} : {
(aws_dms_replication_task.audited_interaction_checksum_outbound_replication[0].replication_task_arn) = aws_dms_replication_task.audited_interaction_checksum_outbound_replication[0].replication_task_id
},
)
}

resource "aws_cloudwatch_metric_alarm" "dms_cdc_latency_source" {
for_each = local.aws_dms_replication_tasks
alarm_name = "dms-cdc-latency-source-${each.value}"
alarm_description = "High CDC source latency for dms replication task for ${each.value}"
namespace = "AWS/DMS"
statistic = "Average"
metric_name = "CDCLatencySource"
comparison_operator = "GreaterThanThreshold"
threshold = 10
evaluation_periods = 2
period = 30
actions_enabled = true
alarm_actions = [aws_sns_topic.dms_alerting.arn]
ok_actions = [aws_sns_topic.dms_alerting.arn]
dimensions = {
ReplicationInstanceIdentifier = aws_dms_replication_instance.dms_replication_instance.replication_instance_id
# We only need to final element of the replication task ID (after the last :)
ReplicationTaskIdentifier = split(":", each.key)[length(split(":", each.key)) - 1]
}
tags = var.tags
}

resource "aws_cloudwatch_metric_alarm" "dms_cdc_latency_target" {
for_each = local.aws_dms_replication_tasks
alarm_name = "dms-cdc-latency-target-${each.value}"
alarm_description = "High CDC target latency for dms replication task for ${each.value}"
namespace = "AWS/DMS"
statistic = "Average"
metric_name = "CDCLatencyTarget"
comparison_operator = "GreaterThanThreshold"
threshold = 10
evaluation_periods = 2
period = 30
actions_enabled = true
alarm_actions = [aws_sns_topic.dms_alerting.arn]
ok_actions = [aws_sns_topic.dms_alerting.arn]
dimensions = {
ReplicationInstanceIdentifier = aws_dms_replication_instance.dms_replication_instance.replication_instance_id
# We only need to final element of the replication task ID (after the last :)
ReplicationTaskIdentifier = split(":", each.key)[length(split(":", each.key)) - 1]
}
tags = var.tags
}

# Pager duty integration

# Get the map of pagerduty integration keys from the modernisation platform account
data "aws_secretsmanager_secret" "pagerduty_integration_keys" {
provider = aws.modernisation-platform
name = "pagerduty_integration_keys"
}

data "aws_secretsmanager_secret_version" "pagerduty_integration_keys" {
provider = aws.modernisation-platform
secret_id = data.aws_secretsmanager_secret.pagerduty_integration_keys.id
}

# Add a local to get the keys
locals {
pagerduty_integration_keys = jsondecode(data.aws_secretsmanager_secret_version.pagerduty_integration_keys.secret_string)
integration_key_lookup = var.dms_config.is-production ? "delius_oracle_prod_alarms" : "delius_oracle_nonprod_alarms"
}

# link the sns topic to the service
# Non-Prod alerts channel: #delius-aws-oracle-dev-alerts
# Prod alerts channel: #delius-aws-oracle-prod-alerts
module "pagerduty_core_alerts" {
depends_on = [
aws_sns_topic.dms_alerting
]
source = "github.com/ministryofjustice/modernisation-platform-terraform-pagerduty-integration?ref=v2.0.0"
sns_topics = [aws_sns_topic.dms_alerting.name]
pagerduty_integration_key = local.pagerduty_integration_keys[local.integration_key_lookup]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ terraform {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
configuration_aliases = [aws.core-vpc, aws.core-network-services, aws.bucket-replication]
configuration_aliases = [aws.core-vpc, aws.core-network-services, aws.bucket-replication, aws.modernisation-platform]
}
archive = {
source = "hashicorp/archive"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ module "dms" {
env_name_to_dms_config_map = var.env_name_to_dms_config_map

providers = {
aws = aws
aws.bucket-replication = aws
aws.core-vpc = aws
aws.core-network-services = aws
aws = aws
aws.bucket-replication = aws
aws.core-vpc = aws
aws.core-network-services = aws
aws.modernisation-platform = aws.modernisation-platform
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ terraform {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
configuration_aliases = [aws.bucket-replication, aws.core-vpc, aws.core-network-services]
configuration_aliases = [aws.bucket-replication, aws.core-vpc, aws.core-network-services, aws.modernisation-platform]
}
archive = {
source = "hashicorp/archive"
Expand Down

0 comments on commit ca6e01d

Please sign in to comment.