Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions infrastructure/terraform/components/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ No requirements.
| <a name="module_sqs_alarms"></a> [sqs\_alarms](#module\_sqs\_alarms) | ../../modules/alarms-sqs | n/a |
| <a name="module_sqs_letter_updates"></a> [sqs\_letter\_updates](#module\_sqs\_letter\_updates) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.1.5/terraform-sqs.zip | n/a |
| <a name="module_sqs_supplier_allocator"></a> [sqs\_supplier\_allocator](#module\_sqs\_supplier\_allocator) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.1.5/terraform-sqs.zip | n/a |
| <a name="module_sqs_supplier_config"></a> [sqs\_supplier\_config](#module\_sqs\_supplier\_config) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.1.5/terraform-sqs.zip | n/a |
| <a name="module_supplier_allocator"></a> [supplier\_allocator](#module\_supplier\_allocator) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/4.0.2/terraform-lambda.zip | n/a |
| <a name="module_supplier_config_ingress"></a> [supplier\_config\_ingress](#module\_supplier\_config\_ingress) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip | n/a |
| <a name="module_supplier_ssl"></a> [supplier\_ssl](#module\_supplier\_ssl) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.26/terraform-ssl.zip | n/a |
| <a name="module_update_letter_queue"></a> [update\_letter\_queue](#module\_update\_letter\_queue) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/4.0.2/terraform-lambda.zip | n/a |
| <a name="module_upsert_letter"></a> [upsert\_letter](#module\_upsert\_letter) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/4.0.2/terraform-lambda.zip | n/a |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
resource "aws_lambda_event_source_mapping" "supplier_config_ingress" {
event_source_arn = module.sqs_supplier_config.sqs_queue_arn
function_name = module.supplier_config_ingress.function_name
batch_size = 10
maximum_batching_window_in_seconds = 5
function_response_types = [
"ReportBatchItemFailures"
]
}
2 changes: 2 additions & 0 deletions infrastructure/terraform/components/api/locals_alarms.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ locals {
letter_updates_transformer = module.letter_updates_transformer.function_name
mi_updates_transformer = module.mi_updates_transformer.function_name
supplier_allocator = module.supplier_allocator.function_name
supplier_config_ingress = module.supplier_config_ingress.function_name
}

sqs_alarm_targets = {
sqs_letter_updates = module.sqs_letter_updates.sqs_queue_name
amendments_queue = module.amendments_queue.sqs_queue_name
letter_status_updates_queue = module.letter_status_updates_queue.sqs_queue_name
sqs_supplier_allocator = module.sqs_supplier_allocator.sqs_queue_name
sqs_supplier_config = module.sqs_supplier_config.sqs_queue_name
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
module "supplier_config_ingress" {
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip"

function_name = "supplier-config-ingress"
description = "Persist supplier config changes"

aws_account_id = var.aws_account_id
component = var.component
environment = var.environment
project = var.project
region = var.region
group = var.group

log_retention_in_days = var.log_retention_in_days
kms_key_arn = module.kms.key_arn

iam_policy_document = {
body = data.aws_iam_policy_document.supplier_config_ingress_lambda.json
}

function_s3_bucket = local.acct.s3_buckets["lambda_function_artefacts"]["id"]
function_code_base_path = local.aws_lambda_functions_dir_path
function_code_dir = "supplier-config-ingress/dist"
function_include_common = true
handler_function_name = "supplierConfigHandler"
runtime = "nodejs22.x"
memory = 512
timeout = 29
log_level = var.log_level

force_lambda_code_deploy = var.force_lambda_code_deploy
enable_lambda_insights = false

log_destination_arn = local.destination_arn
log_subscription_role_arn = local.acct.log_subscription_role_arn

lambda_env_vars = merge(local.common_lambda_env_vars, {})
}
Comment thread
stevebux marked this conversation as resolved.

data "aws_iam_policy_document" "supplier_config_ingress_lambda" {
statement {
sid = "KMSPermissions"
effect = "Allow"

actions = [
"kms:Decrypt",
"kms:GenerateDataKey",
]

resources = [
module.kms.key_arn,
]
}

statement {
sid = "AllowSQSRead"
effect = "Allow"

actions = [
"sqs:ReceiveMessage",
"sqs:DeleteMessage",
"sqs:GetQueueAttributes"
]

resources = [
module.sqs_supplier_config.sqs_queue_arn
]
}

statement {
sid = "AllowConfigDynamoDBWrite"
effect = "Allow"

actions = [
"dynamodb:UpdateItem",
]

resources = [
aws_dynamodb_table.supplier-configuration.arn,
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module "sqs_supplier_config" {
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.1.5/terraform-sqs.zip"

aws_account_id = var.aws_account_id
component = var.component
environment = var.environment
project = var.project
region = var.region
name = "supplier-config"

sqs_kms_key_arn = module.kms.key_arn

visibility_timeout_seconds = 60

create_dlq = true
sqs_policy_overload = data.aws_iam_policy_document.supplier_config_queue_policy.json
}
Comment thread
masl2 marked this conversation as resolved.

data "aws_iam_policy_document" "supplier_config_queue_policy" {
version = "2012-10-17"

statement {
sid = "AllowSNSPermissions"
effect = "Allow"

principals {
type = "Service"
identifiers = ["sns.amazonaws.com"]
}

actions = [
"sqs:SendMessage",
"sqs:ListQueueTags",
"sqs:GetQueueUrl",
"sqs:GetQueueAttributes",
]

resources = [
"arn:aws:sqs:${var.region}:${var.aws_account_id}:${var.project}-${var.environment}-${var.component}-supplier-config-queue"
]

condition {
test = "ArnEquals"
variable = "aws:SourceArn"
values = [module.eventsub.sns_topic.arn]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
resource "aws_sns_topic_subscription" "eventsub_sqs_supplier_config" {
topic_arn = module.eventsub.sns_topic.arn
protocol = "sqs"
endpoint = module.sqs_supplier_config.sqs_queue_arn
raw_message_delivery = true

filter_policy_scope = "MessageBody"
filter_policy = jsonencode({
type = [{ prefix = "uk.nhs.notify.supplier-config" }]
})
}
Loading
Loading