Skip to content

Commit a925afd

Browse files
committed
add secrets for tf and resolve sonar issues
1 parent a96582a commit a925afd

4 files changed

Lines changed: 30 additions & 8 deletions

File tree

infrastructure/instance/mns_publisher.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module "mns_publisher" {
88
immunisation_account_id = var.immunisation_account_id
99
is_temp = local.is_temp
1010
resource_scope = local.resource_scope
11-
sub_environment = strcontains(var.sub_environment, "pr-") ? "immunisation-fhir-api/FHIR/R4-${var.sub_environment}" : "immunisation-fhir-api/FHIR/R4"
11+
imms-base-path = strcontains(var.sub_environment, "pr-") ? "immunisation-fhir-api/FHIR/R4-${var.sub_environment}" : "immunisation-fhir-api/FHIR/R4"
1212
lambda_kms_encryption_key_arn = data.aws_kms_key.existing_lambda_encryption_key.arn
1313
mns_publisher_resource_name_prefix = "${local.resource_scope}-mns-outbound-events"
1414
pds_environment = var.pds_environment

infrastructure/instance/modules/mns_publisher/mns_publisher_lambda.tf

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ resource "aws_lambda_function" "mns_publisher_lambda" {
193193
variables = {
194194
SPLUNK_FIREHOSE_NAME = var.splunk_firehose_stream_name
195195
IMMUNIZATION_ENV = var.resource_scope,
196-
IMMUNIZATION_BASE_PATH = var.sub_environment
196+
IMMUNIZATION_BASE_PATH = var.imms_base_path
197197
PDS_ENV = var.pds_environment
198198
MNS_ENV = var.mns_environment
199199
}
@@ -207,6 +207,30 @@ resource "aws_lambda_function" "mns_publisher_lambda" {
207207
]
208208
}
209209

210+
211+
data "aws_iam_policy_document" "mns_publisher_secrets_policy_document" {
212+
source_policy_documents = [
213+
templatefile("${local.policy_path}/secret_manager.json", {
214+
"account_id" : data.aws_caller_identity.current.account_id,
215+
"pds_environment" : var.pds_environment
216+
}),
217+
]
218+
}
219+
220+
resource "aws_iam_policy" "mns_publisher_lambda_secrets_policy" {
221+
name = "${local.mns_publisher_lambda_name}-secrets-policy"
222+
description = "Allow Lambda to access Secrets Manager"
223+
policy = data.aws_iam_policy_document.mns_publisher_secrets_policy_document.json
224+
}
225+
226+
227+
# Attach the secrets/dynamodb access policy to the Lambda role
228+
resource "aws_iam_role_policy_attachment" "mns_publisher_lambda_secrets_policy_attachment" {
229+
role = aws_iam_role.mns_publisher_lambda_exec_role.name
230+
policy_arn = aws_iam_policy.mns_publish_lambda_secrets_policy.arn
231+
}
232+
233+
210234
resource "aws_cloudwatch_log_group" "mns_publisher_lambda_log_group" {
211235
name = "/aws/lambda/${local.mns_publisher_lambda_name}"
212236
retention_in_days = 30

infrastructure/instance/modules/mns_publisher/variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ variable "resource_scope" {
8181
EOT
8282
}
8383

84-
variable "sub_environment" {
84+
variable "imms_base_path" {
8585
type = string
86-
description = "Sub-environment name, e.g. internal-dev, internal-qa. The value is set in the Makefile"
86+
description = "Base path for the Immunisation FHIR API. Used to construct environment-specific routes (e.g. PR preview paths or default R4 path)."
8787
}
8888

8989
variable "mns_environment" {

lambdas/mns_publisher/src/process_records.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
mns_env = os.getenv("MNS_ENV", "int")
1313

1414

15-
def process_records(records: list[SQSMessage]) -> list[dict]:
15+
def process_records(records: list[SQSMessage]) -> dict[str, list]:
1616
"""
1717
Process multiple SQS records.
1818
Args: records: List of SQS records to process
@@ -23,9 +23,7 @@ def process_records(records: list[SQSMessage]) -> list[dict]:
2323

2424
for record in records:
2525
try:
26-
failed_batch_item = process_record(record, mns_service)
27-
if failed_batch_item:
28-
batch_item_failures.append(failed_batch_item)
26+
process_record(record, mns_service)
2927
except Exception:
3028
message_id = record.get("messageId", "unknown")
3129
batch_item_failures.append({"itemIdentifier": message_id})

0 commit comments

Comments
 (0)