Skip to content

Commit 3820692

Browse files
committed
Merge branch 'main' into feature/CCM-14480_Update_module_sources
2 parents ade7f98 + 121c589 commit 3820692

5 files changed

Lines changed: 108 additions & 10 deletions

File tree

infrastructure/terraform/components/dl/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,15 @@ No requirements.
2020
| <a name="input_default_cloudwatch_event_bus_name"></a> [default\_cloudwatch\_event\_bus\_name](#input\_default\_cloudwatch\_event\_bus\_name) | The name of the default cloudwatch event bus. This is needed as GuardDuty Scan Result events are sent to the default bus | `string` | `"default"` | no |
2121
| <a name="input_default_tags"></a> [default\_tags](#input\_default\_tags) | A map of default tags to apply to all taggable resources within the component | `map(string)` | `{}` | no |
2222
| <a name="input_enable_dynamodb_delete_protection"></a> [enable\_dynamodb\_delete\_protection](#input\_enable\_dynamodb\_delete\_protection) | Enable DynamoDB Delete Protection on all Tables | `bool` | `true` | no |
23+
| <a name="input_enable_event_anomaly_detection"></a> [enable\_event\_anomaly\_detection](#input\_enable\_event\_anomaly\_detection) | Enable CloudWatch anomaly detection alarm for core notifier queue message reception | `bool` | `true` | no |
24+
| <a name="input_enable_event_cache"></a> [enable\_event\_cache](#input\_enable\_event\_cache) | Enable caching of events to an S3 bucket | `bool` | `true` | no |
2325
| <a name="input_enable_mock_mesh"></a> [enable\_mock\_mesh](#input\_enable\_mock\_mesh) | Enable mock mesh access (dev only). Grants lambda permission to read mock-mesh prefix in non-pii bucket. | `bool` | `false` | no |
2426
| <a name="input_enable_pdm_mock"></a> [enable\_pdm\_mock](#input\_enable\_pdm\_mock) | Flag indicating whether to deploy PDM mock API (should be false in production environments) | `bool` | `true` | no |
27+
| <a name="input_enable_sns_delivery_logging"></a> [enable\_sns\_delivery\_logging](#input\_enable\_sns\_delivery\_logging) | Enable SNS Delivery Failure Notifications | `bool` | `true` | no |
2528
| <a name="input_environment"></a> [environment](#input\_environment) | The name of the tfscaffold environment | `string` | n/a | yes |
29+
| <a name="input_event_anomaly_band_width"></a> [event\_anomaly\_band\_width](#input\_event\_anomaly\_band\_width) | The width of the anomaly detection band. Higher values (e.g. 4-6) reduce sensitivity and noise, lower values (e.g. 2-3) increase sensitivity. Recommended: 2-4. | `number` | `3` | no |
30+
| <a name="input_event_anomaly_evaluation_periods"></a> [event\_anomaly\_evaluation\_periods](#input\_event\_anomaly\_evaluation\_periods) | Number of evaluation periods for the anomaly alarm. Each period is defined by event\_anomaly\_period. | `number` | `2` | no |
31+
| <a name="input_event_anomaly_period"></a> [event\_anomaly\_period](#input\_event\_anomaly\_period) | The period in seconds over which the specified statistic is applied for anomaly detection. Minimum 300 seconds (5 minutes). Recommended: 300-600. | `number` | `300` | no |
2632
| <a name="input_eventpub_control_plane_bus_arn"></a> [eventpub\_control\_plane\_bus\_arn](#input\_eventpub\_control\_plane\_bus\_arn) | Event publisher control plane | `string` | n/a | yes |
2733
| <a name="input_eventpub_data_plane_bus_arn"></a> [eventpub\_data\_plane\_bus\_arn](#input\_eventpub\_data\_plane\_bus\_arn) | Event publisher data plane | `string` | n/a | yes |
2834
| <a name="input_force_destroy"></a> [force\_destroy](#input\_force\_destroy) | Flag to force deletion of S3 buckets | `bool` | `false` | no |
@@ -43,14 +49,15 @@ No requirements.
4349
| <a name="input_region"></a> [region](#input\_region) | The AWS Region | `string` | n/a | yes |
4450
| <a name="input_report_scheduler_schedule"></a> [report\_scheduler\_schedule](#input\_report\_scheduler\_schedule) | Schedule to trigger sender reports | `string` | `"cron(30 4 * * ? *)"` | no |
4551
| <a name="input_shared_infra_account_id"></a> [shared\_infra\_account\_id](#input\_shared\_infra\_account\_id) | The AWS Shared Infra Account ID (numeric) | `string` | n/a | yes |
52+
| <a name="input_sns_success_logging_sample_percent"></a> [sns\_success\_logging\_sample\_percent](#input\_sns\_success\_logging\_sample\_percent) | Enable SNS Delivery Successful Sample Percentage | `number` | `0` | no |
4653
| <a name="input_sqs_max_receive_count"></a> [sqs\_max\_receive\_count](#input\_sqs\_max\_receive\_count) | Maximum number of times a message can be received before being sent to the DLQ | `string` | `"3"` | no |
4754
| <a name="input_ttl_poll_schedule"></a> [ttl\_poll\_schedule](#input\_ttl\_poll\_schedule) | Schedule to poll for any overdue TTL records | `string` | `"rate(10 minutes)"` | no |
4855
## Modules
4956

5057
| Name | Source | Version |
5158
|------|--------|---------|
5259
| <a name="module_core_notifier"></a> [core\_notifier](#module\_core\_notifier) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.5/terraform-lambda.zip | n/a |
53-
| <a name="module_eventpub"></a> [eventpub](#module\_eventpub) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.5/terraform-eventpub.zip | n/a |
60+
| <a name="module_eventpub"></a> [eventpub](#module\_eventpub) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-eventpub.zip | n/a |
5461
| <a name="module_file_scanner"></a> [file\_scanner](#module\_file\_scanner) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.5/terraform-lambda.zip | n/a |
5562
| <a name="module_kms"></a> [kms](#module\_kms) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.5/terraform-kms.zip | n/a |
5663
| <a name="module_lambda_apim_key_generation"></a> [lambda\_apim\_key\_generation](#module\_lambda\_apim\_key\_generation) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.5/terraform-lambda.zip | n/a |
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
resource "aws_cloudwatch_metric_alarm" "core_notifier_subscriber_anomaly" {
2+
count = var.enable_event_anomaly_detection ? 1 : 0
3+
4+
alarm_name = "${local.csi}-core-notifier-subscriber-anomaly"
5+
alarm_description = "ANOMALY: Detects anomalous patterns in messages received from the core notifier queue"
6+
comparison_operator = "LessThanLowerOrGreaterThanUpperThreshold"
7+
evaluation_periods = var.event_anomaly_evaluation_periods
8+
threshold_metric_id = "ad1"
9+
treat_missing_data = "notBreaching"
10+
11+
metric_query {
12+
id = "m1"
13+
return_data = true
14+
15+
metric {
16+
metric_name = "NumberOfMessagesReceived"
17+
namespace = "AWS/SQS"
18+
period = var.event_anomaly_period
19+
stat = "Sum"
20+
21+
dimensions = {
22+
QueueName = module.sqs_print_status_handler.sqs_queue_name
23+
}
24+
}
25+
}
26+
27+
metric_query {
28+
id = "ad1"
29+
expression = "ANOMALY_DETECTION_BAND(m1, ${var.event_anomaly_band_width})"
30+
label = "NumberOfMessagesReceived (expected)"
31+
return_data = true
32+
}
33+
34+
tags = merge(
35+
var.default_tags,
36+
{
37+
Name = "${local.csi}-core-notifier-subscriber-anomaly"
38+
}
39+
)
40+
}

infrastructure/terraform/components/dl/modules_eventpub.tf

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module "eventpub" {
2-
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.5/terraform-eventpub.zip"
2+
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-eventpub.zip"
33

44
name = "eventpub"
55

@@ -19,16 +19,19 @@ module "eventpub" {
1919
force_destroy = var.force_destroy
2020

2121
event_cache_buffer_interval = 500
22-
enable_sns_delivery_logging = true
23-
sns_success_logging_sample_percent = 0
22+
enable_sns_delivery_logging = var.enable_sns_delivery_logging
23+
sns_success_logging_sample_percent = var.sns_success_logging_sample_percent
24+
access_logging_bucket = local.acct.s3_buckets["access_logs"]["id"]
2425

2526
event_cache_expiry_days = 30
26-
enable_event_cache = true
27+
enable_event_cache = var.enable_event_cache
28+
data_plane_bus_arn = var.eventpub_data_plane_bus_arn
29+
control_plane_bus_arn = var.eventpub_control_plane_bus_arn
2730

28-
data_plane_bus_arn = var.eventpub_data_plane_bus_arn
29-
control_plane_bus_arn = var.eventpub_control_plane_bus_arn
30-
31-
access_logging_bucket = local.acct.s3_buckets["access_logs"]["id"]
31+
enable_event_anomaly_detection = var.enable_event_anomaly_detection
32+
event_anomaly_band_width = var.event_anomaly_band_width
33+
event_anomaly_evaluation_periods = var.event_anomaly_evaluation_periods
34+
event_anomaly_period = var.event_anomaly_period
3235
}
3336

3437
resource "aws_sns_topic_policy" "eventbridge_publish" {

infrastructure/terraform/components/dl/variables.tf

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,50 @@ variable "sqs_max_receive_count" {
225225
description = "Maximum number of times a message can be received before being sent to the DLQ"
226226
default = "3"
227227
}
228+
229+
variable "enable_event_cache" {
230+
type = bool
231+
description = "Enable caching of events to an S3 bucket"
232+
default = true
233+
}
234+
235+
variable "enable_sns_delivery_logging" {
236+
type = bool
237+
description = "Enable SNS Delivery Failure Notifications"
238+
default = true
239+
}
240+
241+
variable "sns_success_logging_sample_percent" {
242+
type = number
243+
description = "Enable SNS Delivery Successful Sample Percentage"
244+
default = 0
245+
}
246+
247+
variable "enable_event_anomaly_detection" {
248+
type = bool
249+
description = "Enable CloudWatch anomaly detection alarm for core notifier queue message reception"
250+
default = true
251+
}
252+
253+
variable "event_anomaly_evaluation_periods" {
254+
type = number
255+
description = "Number of evaluation periods for the anomaly alarm. Each period is defined by event_anomaly_period."
256+
default = 2
257+
}
258+
259+
variable "event_anomaly_period" {
260+
type = number
261+
description = "The period in seconds over which the specified statistic is applied for anomaly detection. Minimum 300 seconds (5 minutes). Recommended: 300-600."
262+
default = 300
263+
}
264+
265+
variable "event_anomaly_band_width" {
266+
type = number
267+
description = "The width of the anomaly detection band. Higher values (e.g. 4-6) reduce sensitivity and noise, lower values (e.g. 2-3) increase sensitivity. Recommended: 2-4."
268+
default = 3
269+
270+
validation {
271+
condition = var.event_anomaly_band_width >= 2 && var.event_anomaly_band_width <= 10
272+
error_message = "Band width must be between 2 and 10"
273+
}
274+
}

scripts/config/pre-commit.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ repos:
1515
- id: detect-private-key
1616
exclude: |
1717
(?x)^(
18-
.*/validate-private-key\.test\.ts
18+
.*/validate-private-key\.test\.ts |
19+
utils/utils/src/__tests__/key-generation/get-private-key.test.ts
1920
)$
2021
- id: end-of-file-fixer
2122
- id: forbid-new-submodules

0 commit comments

Comments
 (0)