Skip to content

Commit db24dd1

Browse files
committed
Migrate supplier updates so that they pass through new topic
1 parent 6c42d09 commit db24dd1

7 files changed

Lines changed: 12 additions & 29 deletions

File tree

infrastructure/terraform/components/api/locals.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ locals {
2727
SUPPLIER_ID_HEADER = "nhsd-supplier-id",
2828
APIM_CORRELATION_HEADER = "nhsd-correlation-id",
2929
DOWNLOAD_URL_TTL_SECONDS = 60
30-
SNS_TOPIC_ARN = "${module.eventsub.eventsub_topic.arn}",
30+
AMENDMENTS_TOPIC_ARN = "${module.eventsub.amendments_topic.arn}",
3131
EVENT_SOURCE = "/data-plane/supplier-api/${var.group}/${var.environment}/letters"
3232
}
3333

infrastructure/terraform/components/api/module_lambda_letter_status_update.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ data "aws_iam_policy_document" "letter_status_update" {
9191
]
9292

9393
resources = [
94-
module.eventsub.eventsub_topic.arn
94+
module.eventsub.amendments_topic.arn
9595
]
9696
}
9797
}

infrastructure/terraform/components/api/module_sqs_letter_updates.tf

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,6 @@ module "sqs_letter_updates" {
1818

1919
data "aws_iam_policy_document" "letter_updates_queue_policy" {
2020
version = "2012-10-17"
21-
statement {
22-
sid = "AllowSNSToSendMessage"
23-
effect = "Allow"
24-
25-
principals {
26-
type = "Service"
27-
identifiers = ["sns.amazonaws.com"]
28-
}
29-
30-
actions = [
31-
"sqs:SendMessage"
32-
]
33-
34-
resources = [
35-
"arn:aws:sqs:${var.region}:${var.aws_account_id}:${var.project}-${var.environment}-${var.component}-letter-updates-queue"
36-
]
37-
38-
condition {
39-
test = "ArnEquals"
40-
variable = "aws:SourceArn"
41-
values = [module.eventsub.eventsub_topic.arn]
42-
}
43-
}
4421

4522
statement {
4623
sid = "AllowSNSPermissions"
@@ -65,7 +42,7 @@ data "aws_iam_policy_document" "letter_updates_queue_policy" {
6542
condition {
6643
test = "ArnEquals"
6744
variable = "aws:SourceArn"
68-
values = [module.eventsub.eventsub_topic.arn]
45+
values = [module.eventsub.eventsub_topic.arn, module.eventsub.amendments_topic.arn]
6946
}
7047
}
7148
}

infrastructure/terraform/components/api/sns_topic_subscription_eventsub_sqs_letter_updates.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@ resource "aws_sns_topic_subscription" "eventsub_sqs_letter_updates" {
33
protocol = "sqs"
44
endpoint = module.sqs_letter_updates.sqs_queue_arn
55
}
6+
7+
resource "aws_sns_topic_subscription" "eventsub_sqs_letter_updates" {
8+
topic_arn = module.eventsub.amendments_topic.arn
9+
protocol = "sqs"
10+
endpoint = module.sqs_letter_updates.sqs_queue_arn
11+
}

lambdas/api-handler/src/config/env.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const EnvVarsSchema = z.object({
1111
MAX_LIMIT: z.coerce.number().int().optional(),
1212
QUEUE_URL: z.coerce.string().optional(),
1313
EVENT_SOURCE: z.string(),
14-
SNS_TOPIC_ARN: z.string(),
14+
AMENDMENTS_TOPIC_ARN: z.string(),
1515
});
1616

1717
export type EnvVars = z.infer<typeof EnvVarsSchema>;

lambdas/api-handler/src/handlers/__tests__/letter-status-update.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ describe("createLetterStatusUpdateHandler", () => {
117117
i + 1,
118118
expect.objectContaining({
119119
input: expect.objectContaining({
120-
TopicArn: mockedDeps.env.SNS_TOPIC_ARN,
120+
TopicArn: mockedDeps.env.AMENDMENTS_TOPIC_ARN,
121121
Message: JSON.stringify(
122122
mapLetterToCloudEvent(
123123
updateLetterCommands[i] as Letter,

lambdas/api-handler/src/handlers/letter-status-update.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default function createLetterStatusUpdateHandler(
3131
deps.env.EVENT_SOURCE,
3232
);
3333
await deps.snsClient.send(
34-
buildSnsCommand(letterEvent, deps.env.SNS_TOPIC_ARN),
34+
buildSnsCommand(letterEvent, deps.env.AMENDMENTS_TOPIC_ARN),
3535
);
3636
} catch (error) {
3737
deps.logger.error(

0 commit comments

Comments
 (0)