Skip to content

Commit ad82353

Browse files
committed
Add allocation lambda
1 parent 4f83cfe commit ad82353

5 files changed

Lines changed: 86 additions & 7 deletions

File tree

infrastructure/terraform/components/api/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ No requirements.
3838

3939
| Name | Source | Version |
4040
|------|--------|---------|
41+
| <a name="module_allocation_lambda"></a> [allocation\_lambda](#module\_allocation\_lambda) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.26/terraform-lambda.zip | n/a |
4142
| <a name="module_authorizer_lambda"></a> [authorizer\_lambda](#module\_authorizer\_lambda) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip | n/a |
4243
| <a name="module_domain_truststore"></a> [domain\_truststore](#module\_domain\_truststore) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.26/terraform-s3bucket.zip | n/a |
4344
| <a name="module_eventpub"></a> [eventpub](#module\_eventpub) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.26/terraform-eventpub.zip | n/a |
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
module "allocation_lambda" {
2+
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.26/terraform-lambda.zip"
3+
4+
function_name = "allocate_supplier"
5+
description = "Lambda function for allocating supplier"
6+
7+
aws_account_id = var.aws_account_id
8+
component = var.component
9+
environment = var.environment
10+
project = var.project
11+
region = var.region
12+
group = var.group
13+
14+
log_retention_in_days = var.log_retention_in_days
15+
kms_key_arn = module.kms.key_arn
16+
17+
iam_policy_document = {
18+
body = data.aws_iam_policy_document.allocation_lambda.json
19+
}
20+
21+
function_s3_bucket = local.acct.s3_buckets["lambda_function_artefacts"]["id"]
22+
function_code_base_path = local.aws_lambda_functions_dir_path
23+
function_code_dir = "allocation/dist"
24+
function_include_common = true
25+
handler_function_name = "handler"
26+
runtime = "nodejs22.x"
27+
memory = 128
28+
timeout = 29
29+
log_level = var.log_level
30+
31+
force_lambda_code_deploy = var.force_lambda_code_deploy
32+
enable_lambda_insights = false
33+
34+
send_to_firehose = true
35+
log_destination_arn = local.destination_arn
36+
log_subscription_role_arn = local.acct.log_subscription_role_arn
37+
38+
lambda_env_vars = {
39+
QUEUE_URL = module.amendments_queue.sqs_queue_url
40+
}
41+
}
42+
43+
44+
data "aws_iam_policy_document" "allocation_lambda" {
45+
statement {
46+
sid = "KMSPermissions"
47+
effect = "Allow"
48+
49+
actions = [
50+
"kms:Decrypt",
51+
"kms:GenerateDataKey",
52+
]
53+
54+
resources = [
55+
module.kms.key_arn,
56+
]
57+
}
58+
59+
statement {
60+
sid = "AllowQueueAccess"
61+
effect = "Allow"
62+
63+
actions = [
64+
"sqs:SendMessage",
65+
"sqs:GetQueueAttributes",
66+
]
67+
68+
resources = [
69+
module.amendments_queue.sqs_queue_arn
70+
]
71+
}
72+
}

infrastructure/terraform/components/api/module_sqs_letter_updates.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ data "aws_iam_policy_document" "letter_updates_queue_policy" {
6666
test = "ArnEquals"
6767
variable = "aws:SourceArn"
6868
values = [
69-
module.eventsub.sns_topic.arn,
7069
module.eventsub.sns_topic_clone.arn
7170
]
7271
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
resource "aws_sns_topic_subscription" "allocation_lambda" {
2+
topic_arn = module.eventsub.sns_topic_event_bus.arn
3+
protocol = "lambda"
4+
endpoint = module.allocation_lambda.function_arn
5+
}
6+
7+
resource "aws_lambda_permission" "allocation_lambda_sns" {
8+
statement_id = "AllowExecutionFromSNS"
9+
action = "lambda:InvokeFunction"
10+
function_name = module.allocation_lambda.function_name
11+
principal = "sns.amazonaws.com"
12+
source_arn = module.eventsub.sns_topic_event_bus.arn
13+
}

infrastructure/terraform/components/api/sns_topic_subscription_eventsub_sqs_letter_updates.tf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
resource "aws_sns_topic_subscription" "eventsub_sqs_letter_updates" {
2-
topic_arn = module.eventsub.sns_topic.arn
3-
protocol = "sqs"
4-
endpoint = module.sqs_letter_updates.sqs_queue_arn
5-
}
6-
71
resource "aws_sns_topic_subscription" "eventsub_sqs_letter_updates_clone" {
82
topic_arn = module.eventsub.sns_topic_clone.arn
93
protocol = "sqs"

0 commit comments

Comments
 (0)