Skip to content

Commit 1d8701d

Browse files
authored
CCM-13451: Letter Updates SQS Queue Policy Dependency Fix (#282)
* CCM-13451: Queue policy dependency fix * CCM-13451: Queue policy dependency fix
1 parent 0ac449a commit 1d8701d

File tree

6 files changed

+73
-76
lines changed

6 files changed

+73
-76
lines changed

infrastructure/terraform/components/api/event_source_mapping_status_updates_to_handler.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ resource "aws_lambda_event_source_mapping" "status_updates_sqs_to_status_update_
66
scaling_config { maximum_concurrency = 10 }
77

88
depends_on = [
9-
module.letter_status_updates_queue, # ensures queue exists
10-
module.letter_status_update # ensures update handler exists
9+
module.letter_status_updates_queue, # ensures queue exists
10+
module.letter_status_update # ensures update handler exists
1111
]
1212
}

infrastructure/terraform/components/api/locals.tf

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ locals {
55
root_domain_nameservers = local.acct.route53_zone_nameservers["supplier-api"]
66

77
openapi_spec = templatefile("${path.module}/resources/spec.tmpl.json", {
8-
APIG_EXECUTION_ROLE_ARN = aws_iam_role.api_gateway_execution_role.arn
9-
AWS_REGION = var.region
10-
AUTHORIZER_LAMBDA_ARN = module.authorizer_lambda.function_arn
11-
GET_LETTER_LAMBDA_ARN = module.get_letter.function_arn
12-
GET_LETTERS_LAMBDA_ARN = module.get_letters.function_arn
13-
GET_LETTER_DATA_LAMBDA_ARN = module.get_letter_data.function_arn
14-
GET_STATUS_LAMBDA_ARN = module.get_status.function_arn
15-
PATCH_LETTER_LAMBDA_ARN = module.patch_letter.function_arn
16-
POST_LETTERS_LAMBDA_ARN = module.post_letters.function_arn
17-
POST_MI_LAMBDA_ARN = module.post_mi.function_arn
8+
APIG_EXECUTION_ROLE_ARN = aws_iam_role.api_gateway_execution_role.arn
9+
AWS_REGION = var.region
10+
AUTHORIZER_LAMBDA_ARN = module.authorizer_lambda.function_arn
11+
GET_LETTER_LAMBDA_ARN = module.get_letter.function_arn
12+
GET_LETTERS_LAMBDA_ARN = module.get_letters.function_arn
13+
GET_LETTER_DATA_LAMBDA_ARN = module.get_letter_data.function_arn
14+
GET_STATUS_LAMBDA_ARN = module.get_status.function_arn
15+
PATCH_LETTER_LAMBDA_ARN = module.patch_letter.function_arn
16+
POST_LETTERS_LAMBDA_ARN = module.post_letters.function_arn
17+
POST_MI_LAMBDA_ARN = module.post_mi.function_arn
1818
})
1919

2020
destination_arn = "arn:aws:logs:${var.region}:${var.shared_infra_account_id}:destination:nhs-main-obs-firehose-logs"
@@ -23,7 +23,7 @@ locals {
2323
LETTERS_TABLE_NAME = aws_dynamodb_table.letters.name,
2424
MI_TABLE_NAME = aws_dynamodb_table.mi.name,
2525
LETTER_TTL_HOURS = 12960, # 18 months * 30 days * 24 hours
26-
MI_TTL_HOURS = 2160 # 90 days * 24 hours
26+
MI_TTL_HOURS = 2160 # 90 days * 24 hours
2727
SUPPLIER_ID_HEADER = "nhsd-supplier-id",
2828
APIM_CORRELATION_HEADER = "nhsd-correlation-id",
2929
DOWNLOAD_URL_TTL_SECONDS = 60

infrastructure/terraform/components/api/module_authorizer_lambda.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ module "authorizer_lambda" {
3838
lambda_env_vars = {
3939
CLOUDWATCH_NAMESPACE = "/aws/api-gateway/supplier/alarms",
4040
CLIENT_CERTIFICATE_EXPIRATION_ALERT_DAYS = 14,
41-
APIM_SUPPLIER_ID_HEADER = "NHSD-Supplier-ID",
41+
APIM_SUPPLIER_ID_HEADER = "NHSD-Supplier-ID",
4242
SUPPLIERS_TABLE_NAME = aws_dynamodb_table.suppliers.name
4343
}
4444
}

infrastructure/terraform/components/api/module_lambda_get_letter_data.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ data "aws_iam_policy_document" "get_letter_data_lambda" {
6969
}
7070

7171
statement {
72-
sid = "S3GetObjectForPresign"
73-
actions = [
72+
sid = "S3GetObjectForPresign"
73+
actions = [
7474
"s3:GetObject",
75-
"s3:ListBucket"] # allows 404 response instead of 403 if object missing
75+
"s3:ListBucket"] # allows 404 response instead of 403 if object missing
7676
resources = ["${module.s3bucket_test_letters.arn}/*"]
7777
}
7878
}

infrastructure/terraform/components/api/module_sqs_letter_updates.tf

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,60 @@ module "sqs_letter_updates" {
1212

1313
visibility_timeout_seconds = 60
1414

15-
create_dlq = true
15+
create_dlq = true
16+
sqs_policy_overload = data.aws_iam_policy_document.letter_updates_queue_policy.json
17+
}
18+
19+
data "aws_iam_policy_document" "letter_updates_queue_policy" {
20+
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.sns_topic.arn]
42+
}
43+
}
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+
}
1671
}

infrastructure/terraform/components/api/sqs_queue_policy_letter_updates.tf

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)