Skip to content

Commit 72fb30f

Browse files
committed
CCM-7939: pipe dlq and retry settings
1 parent efd185d commit 72fb30f

File tree

6 files changed

+106
-20
lines changed

6 files changed

+106
-20
lines changed

infrastructure/terraform/components/acct/module_sandbox_kms.tf

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,35 @@ data "aws_iam_policy_document" "kms" {
5454
]
5555
}
5656
}
57+
58+
statement {
59+
sid = "AllowLogDeliveryEncrypt"
60+
effect = "Allow"
61+
62+
principals {
63+
type = "Service"
64+
65+
identifiers = [
66+
"delivery.logs.amazonaws.com"
67+
]
68+
}
69+
70+
actions = [
71+
"kms:Decrypt",
72+
"kms:GenerateDataKey*",
73+
]
74+
75+
resources = [
76+
"*",
77+
]
78+
79+
condition {
80+
test = "StringLike"
81+
variable = "kms:EncryptionContext:SourceArn"
82+
83+
values = [
84+
"arn:aws:logs:${var.region}:${var.aws_account_id}:*",
85+
]
86+
}
87+
}
5788
}

infrastructure/terraform/components/app/module_kms.tf

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,35 @@ data "aws_iam_policy_document" "kms" {
7575
]
7676
}
7777
}
78+
79+
statement {
80+
sid = "AllowLogDeliveryEncrypt"
81+
effect = "Allow"
82+
83+
principals {
84+
type = "Service"
85+
86+
identifiers = [
87+
"delivery.logs.amazonaws.com"
88+
]
89+
}
90+
91+
actions = [
92+
"kms:Decrypt",
93+
"kms:GenerateDataKey*",
94+
]
95+
96+
resources = [
97+
"*",
98+
]
99+
100+
condition {
101+
test = "StringLike"
102+
variable = "kms:EncryptionContext:SourceArn"
103+
104+
values = [
105+
"arn:aws:logs:${var.region}:${var.aws_account_id}:*",
106+
]
107+
}
108+
}
78109
}

infrastructure/terraform/modules/backend-api/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ No requirements.
5454
| <a name="module_s3bucket_quarantine"></a> [s3bucket\_quarantine](#module\_s3bucket\_quarantine) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/s3bucket | v1.0.8 |
5555
| <a name="module_sqs_sftp_upload"></a> [sqs\_sftp\_upload](#module\_sqs\_sftp\_upload) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/sqs | v2.0.1 |
5656
| <a name="module_sqs_template_table_events"></a> [sqs\_template\_table\_events](#module\_sqs\_template\_table\_events) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/sqs | v2.0.8 |
57+
| <a name="module_sqs_template_table_events_pipe_dlq"></a> [sqs\_template\_table\_events\_pipe\_dlq](#module\_sqs\_template\_table\_events\_pipe\_dlq) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/sqs | v2.0.8 |
5758
| <a name="module_sqs_validate_letter_template_files"></a> [sqs\_validate\_letter\_template\_files](#module\_sqs\_validate\_letter\_template\_files) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/sqs | v2.0.1 |
5859
| <a name="module_submit_template_lambda"></a> [submit\_template\_lambda](#module\_submit\_template\_lambda) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/lambda | v2.0.4 |
5960
| <a name="module_update_template_lambda"></a> [update\_template\_lambda](#module\_update\_template\_lambda) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/lambda | v2.0.4 |
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
module "sqs_template_table_events" {
22
source = "git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/sqs?ref=v2.0.8"
33

4-
aws_account_id = var.aws_account_id
5-
component = var.component
6-
environment = var.environment
7-
project = var.project
8-
region = var.region
9-
name = "template-table-events"
10-
fifo_queue = true
11-
content_based_deduplication = true
12-
4+
aws_account_id = var.aws_account_id
5+
component = var.component
6+
environment = var.environment
7+
project = var.project
8+
region = var.region
9+
name = "template-table-events"
10+
fifo_queue = true
1311
sqs_kms_key_arn = var.kms_key_arn
1412
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module "sqs_template_table_events_pipe_dlq" {
2+
source = "git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/sqs?ref=v2.0.8"
3+
4+
aws_account_id = var.aws_account_id
5+
component = var.component
6+
environment = var.environment
7+
project = var.project
8+
region = var.region
9+
name = "template-table-events-pipe-dead-letter"
10+
sqs_kms_key_arn = var.kms_key_arn
11+
}

infrastructure/terraform/modules/backend-api/pipes_pipe_template_table_events.tf

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,28 @@ resource "aws_pipes_pipe" "template_table_events" {
88

99
source_parameters {
1010
dynamodb_stream_parameters {
11-
starting_position = "TRIM_HORIZON"
11+
starting_position = "TRIM_HORIZON"
12+
maximum_retry_attempts = 3
13+
maximum_record_age_in_seconds = -1
14+
maximum_batching_window_in_seconds = 5
15+
16+
dead_letter_config {
17+
arn = module.sqs_template_table_events_pipe_dlq.sqs_queue_arn
18+
}
1219
}
1320
}
1421

1522
target_parameters {
1623
sqs_queue_parameters {
17-
message_group_id = "$.dynamodb.Keys.id.S"
24+
message_group_id = "$.dynamodb.Keys.id.S"
25+
message_deduplication_id = "$.eventID"
1826
}
1927
}
2028

2129
log_configuration {
22-
level = "ERROR"
30+
level = "ERROR"
31+
include_execution_data = ["ALL"]
32+
2333
cloudwatch_logs_log_destination {
2434
log_group_arn = aws_cloudwatch_log_group.pipe_template_table_events.arn
2535
}
@@ -61,7 +71,7 @@ data "aws_iam_policy_document" "pipe_template_table_events" {
6171
version = "2012-10-17"
6272

6373
statement {
64-
sid = "AllowDDBStreamRead"
74+
sid = "AllowDynamoStreamRead"
6575
effect = "Allow"
6676
actions = [
6777
"dynamodb:DescribeStream",
@@ -73,24 +83,28 @@ data "aws_iam_policy_document" "pipe_template_table_events" {
7383
}
7484

7585
statement {
76-
sid = "AllowSQSSendMessage"
77-
effect = "Allow"
78-
actions = ["sqs:SendMessage"]
79-
resources = [module.sqs_template_table_events.sqs_queue_arn]
86+
sid = "AllowSqsSendMessage"
87+
effect = "Allow"
88+
actions = ["sqs:SendMessage"]
89+
resources = [
90+
module.sqs_template_table_events.sqs_queue_arn,
91+
module.sqs_template_table_events_pipe_dlq.sqs_queue_arn,
92+
]
8093
}
8194

8295
statement {
83-
sid = "AllowSqsKMS"
96+
sid = "AllowKmsUsage"
8497
effect = "Allow"
8598
actions = [
8699
"kms:Decrypt",
87-
"kms:GenerateDataKey"
100+
"kms:Encrypt",
101+
"kms:GenerateDataKey*"
88102
]
89103
resources = [var.kms_key_arn]
90104
}
91105

92106
statement {
93-
sid = "AllowDynamoKMS"
107+
sid = "AllowDynamoKms"
94108
effect = "Allow"
95109
actions = ["kms:Decrypt"]
96110
resources = [local.dynamodb_kms_key_arn]

0 commit comments

Comments
 (0)