Skip to content

Commit a65be7b

Browse files
stevebuxnhsd-david-wass
authored andcommitted
Create filters on SNS topic subscriptions
1 parent 74d73ee commit a65be7b

3 files changed

Lines changed: 21 additions & 27 deletions

File tree

infrastructure/terraform/components/api/module_sqs_letter_updates.tf

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module "sqs_letter_updates" {
1616
sqs_policy_overload = data.aws_iam_policy_document.letter_updates_queue_policy.json
1717
}
1818

19+
1920
data "aws_iam_policy_document" "letter_updates_queue_policy" {
2021
version = "2012-10-17"
2122
statement {
@@ -41,31 +42,4 @@ data "aws_iam_policy_document" "letter_updates_queue_policy" {
4142
values = [module.eventsub.sns_topic.arn]
4243
}
4344
}
44-
45-
statement {
46-
sid = "AllowSNSPermissions"
47-
effect = "Allow"
48-
49-
principals {
50-
type = "Service"
51-
identifiers = ["sns.amazonaws.com"]
52-
}
53-
54-
actions = [
55-
"sqs:SendMessage",
56-
"sqs:ListQueueTags",
57-
"sqs:GetQueueUrl",
58-
"sqs:GetQueueAttributes",
59-
]
60-
61-
resources = [
62-
"arn:aws:sqs:${var.region}:${var.aws_account_id}:${var.project}-${var.environment}-${var.component}-letter-updates-queue"
63-
]
64-
65-
condition {
66-
test = "ArnEquals"
67-
variable = "aws:SourceArn"
68-
values = [module.eventsub.sns_topic.arn]
69-
}
70-
}
7145
}

infrastructure/terraform/components/api/sns_topic_subscription_eventsub_sqs_letter_updates.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,11 @@ resource "aws_sns_topic_subscription" "eventsub_sqs_letter_updates" {
22
topic_arn = module.eventsub.sns_topic.arn
33
protocol = "sqs"
44
endpoint = module.sqs_letter_updates.sqs_queue_arn
5+
6+
raw_message_delivery = true
7+
8+
filter_policy_scope = "MessageBody"
9+
filter_policy = jsonencode({
10+
type = [{ prefix = "uk.nhs.notify.supplier-api.letter" }]
11+
})
512
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
resource "aws_sns_topic_subscription" "eventsub_sqs_supplier_allocator" {
2+
# The supplier allocator queue will be introduced by another ticket. For now, route events directly to the letter updates queue.
3+
topic_arn = module.eventsub.sns_topic.arn
4+
protocol = "sqs"
5+
endpoint = module.sqs_letter_updates.sqs_queue_arn
6+
7+
raw_message_delivery = true
8+
9+
filter_policy_scope = "MessageBody"
10+
filter_policy = jsonencode({
11+
type = [{ prefix = "uk.nhs.notify.letter-rendering.letter-request.prepared" }]
12+
})
13+
}

0 commit comments

Comments
 (0)