|
| 1 | +module "allocate_letter" { |
| 2 | + source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip" |
| 3 | + |
| 4 | + function_name = "allocate_letter" |
| 5 | + description = "Allocate a letter to a 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.allocate_letter_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 = "allocate-letter/dist" |
| 24 | + function_include_common = true |
| 25 | + handler_function_name = "allocateLetterHandler" |
| 26 | + runtime = "nodejs22.x" |
| 27 | + memory = 512 |
| 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 | + log_destination_arn = local.destination_arn |
| 35 | + log_subscription_role_arn = local.acct.log_subscription_role_arn |
| 36 | + |
| 37 | + lambda_env_vars = merge(local.common_lambda_env_vars, { |
| 38 | + VARIANT_MAP = jsonencode(var.letter_variant_map) |
| 39 | + ALLOCATED_LETTERS_QUEUE_URL = module.sqs_allocated_letters.sqs_queue_url |
| 40 | + }) |
| 41 | +} |
| 42 | + |
| 43 | +data "aws_iam_policy_document" "allocate_letter_lambda" { |
| 44 | + statement { |
| 45 | + sid = "KMSPermissions" |
| 46 | + effect = "Allow" |
| 47 | + |
| 48 | + actions = [ |
| 49 | + "kms:Decrypt", |
| 50 | + "kms:GenerateDataKey", |
| 51 | + ] |
| 52 | + |
| 53 | + resources = [ |
| 54 | + module.kms.key_arn, |
| 55 | + ] |
| 56 | + } |
| 57 | + |
| 58 | + statement { |
| 59 | + sid = "AllowSQSRead" |
| 60 | + effect = "Allow" |
| 61 | + |
| 62 | + actions = [ |
| 63 | + "sqs:ReceiveMessage", |
| 64 | + "sqs:DeleteMessage", |
| 65 | + "sqs:GetQueueAttributes" |
| 66 | + ] |
| 67 | + |
| 68 | + resources = [ |
| 69 | + module.sqs_letter_updates.sqs_queue_arn |
| 70 | + ] |
| 71 | + } |
| 72 | + |
| 73 | + statement { |
| 74 | + sid = "AllowSQSWrite" |
| 75 | + effect = "Allow" |
| 76 | + |
| 77 | + actions = [ |
| 78 | + "sqs:SendMessage" |
| 79 | + ] |
| 80 | + |
| 81 | + resources = [ |
| 82 | + module.sqs_allocated_letters.sqs_queue_arn |
| 83 | + ] |
| 84 | + } |
| 85 | +} |
0 commit comments