Skip to content

Commit ad0da5a

Browse files
authored
VED:1099: Create Test SQS Queue for MNS (#1268)
* create temporary sqs queue for mns publish notification
1 parent 8e22a92 commit ad0da5a

19 files changed

Lines changed: 287 additions & 80 deletions

File tree

infrastructure/instance/.terraform.lock.hcl

Lines changed: 29 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

infrastructure/instance/environments/dev/internal-dev/variables.tfvars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ environment = "dev"
22
immunisation_account_id = "345594581768"
33
dspp_core_account_id = "603871901111"
44
pds_environment = "int"
5-
mns_environment = "int"
5+
mns_environment = "dev"
66
error_alarm_notifications_enabled = true
77
create_mesh_processor = false
88
has_sub_environment_scope = true

infrastructure/instance/environments/dev/internal-qa/variables.tfvars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ environment = "dev"
22
immunisation_account_id = "345594581768"
33
dspp_core_account_id = "603871901111"
44
pds_environment = "int"
5-
mns_environment = "int"
5+
mns_environment = "dev"
66
error_alarm_notifications_enabled = false
77
mns_publisher_feature_enabled = true
88
create_mesh_processor = false

infrastructure/instance/environments/dev/pr/variables.tfvars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ environment = "dev"
22
immunisation_account_id = "345594581768"
33
dspp_core_account_id = "603871901111"
44
pds_environment = "int"
5-
mns_environment = "int"
5+
mns_environment = "dev"
66
error_alarm_notifications_enabled = false
77
mns_publisher_feature_enabled = true # Switch this off once tested fully e2e in Lambda branch
88
create_mesh_processor = false

infrastructure/instance/environments/dev/ref/variables.tfvars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ environment = "dev"
22
immunisation_account_id = "345594581768"
33
dspp_core_account_id = "603871901111"
44
pds_environment = "ref"
5-
mns_environment = "int"
5+
mns_environment = "dev"
66
error_alarm_notifications_enabled = true
77
create_mesh_processor = false
88
has_sub_environment_scope = true

infrastructure/instance/mns_publisher.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ module "mns_publisher" {
77
enable_lambda_alarm = var.error_alarm_notifications_enabled # consider just INT and PROD
88
immunisation_account_id = var.immunisation_account_id
99
is_temp = local.is_temp
10+
enable_mns_test_queue = var.mns_environment == "dev"
1011
resource_scope = local.resource_scope
1112
imms_base_path = strcontains(var.sub_environment, "pr-") ? "immunisation-fhir-api/FHIR/R4-${var.sub_environment}" : "immunisation-fhir-api/FHIR/R4"
1213
lambda_kms_encryption_key_arn = data.aws_kms_key.existing_lambda_encryption_key.arn
1314
mns_publisher_resource_name_prefix = "${local.resource_scope}-mns-outbound-events"
15+
mns_test_notification_name_prefix = "${local.resource_scope}-mns-test-notification"
1416
secrets_manager_policy_path = "${local.policy_path}/secret_manager.json"
1517
account_id = data.aws_caller_identity.current.account_id
1618
pds_environment = var.pds_environment

infrastructure/instance/modules/mns_publisher/mns_publisher_lambda.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ resource "aws_lambda_function" "mns_publisher_lambda" {
192192
environment {
193193
variables = {
194194
SPLUNK_FIREHOSE_NAME = var.splunk_firehose_stream_name
195+
MNS_TEST_QUEUE_URL = var.enable_mns_test_queue ? aws_sqs_queue.mns_test_notification[0].url : ""
195196
IMMUNIZATION_ENV = var.resource_scope,
196197
IMMUNIZATION_BASE_PATH = var.imms_base_path
197198
PDS_ENV = var.pds_environment
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
resource "aws_sqs_queue" "mns_test_notification" {
2+
count = var.enable_mns_test_queue ? 1 : 0
3+
name = "${var.mns_test_notification_name_prefix}-queue"
4+
fifo_queue = false
5+
message_retention_seconds = 86400
6+
visibility_timeout_seconds = 300
7+
}
8+
9+
10+
data "aws_iam_policy_document" "mns_test_notification_sqs_policy" {
11+
count = var.enable_mns_test_queue ? 1 : 0
12+
statement {
13+
sid = "mns-test-notification-allow-lambda-access"
14+
effect = "Allow"
15+
16+
principals {
17+
type = "AWS"
18+
identifiers = [aws_iam_role.mns_publisher_lambda_exec_role.arn]
19+
}
20+
21+
actions = [
22+
"sqs:SendMessage",
23+
]
24+
25+
resources = [
26+
aws_sqs_queue.mns_test_notification[0].arn
27+
]
28+
}
29+
}
30+
31+
resource "aws_sqs_queue_policy" "mns_test_notification_sqs" {
32+
count = var.enable_mns_test_queue ? 1 : 0
33+
queue_url = aws_sqs_queue.mns_test_notification[0].id
34+
policy = data.aws_iam_policy_document.mns_test_notification_sqs_policy[0].json
35+
}
36+
37+
output "mns_test_queue_url" {
38+
value = var.enable_mns_test_queue ? aws_sqs_queue.mns_test_notification[0].url : null
39+
description = "URL of the MNS test notifications queue"
40+
}
41+
42+
output "mns_test_queue_arn" {
43+
value = var.enable_mns_test_queue ? aws_sqs_queue.mns_test_notification[0].arn : null
44+
description = "ARN of the MNS test notifications queue"
45+
}

infrastructure/instance/modules/mns_publisher/variables.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,15 @@ variable "account_id" {
102102
variable "secrets_manager_policy_path" {
103103
type = string
104104
description = "Path to the IAM policy JSON template for Secrets Manager access (e.g., ./policies/secret_manager.json)."
105+
}
106+
107+
variable "mns_test_notification_name_prefix" {
108+
type = string
109+
description = "The prefix for the name of resources for testing mns notification"
110+
}
111+
112+
variable "enable_mns_test_queue" {
113+
description = "Enable test SQS queue for MNS notifications (dev only)"
114+
type = bool
115+
default = false
105116
}

infrastructure/instance/outputs.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,13 @@ output "id_sync_queue_arn" {
1818
description = "The ARN of the ID Sync (MNS NHS Number change) SQS queue"
1919
value = aws_sqs_queue.id_sync_queue.arn
2020
}
21+
22+
output "mns_test_queue_url" {
23+
value = var.mns_publisher_feature_enabled ? module.mns_publisher[0].mns_test_queue_url : null
24+
description = "URL of the MNS test notifications queue (from mns_publisher module)"
25+
}
26+
27+
output "mns_test_queue_arn" {
28+
value = var.mns_publisher_feature_enabled ? module.mns_publisher[0].mns_test_queue_arn : null
29+
description = "ARN of the MNS test notifications queue (from mns_publisher module)"
30+
}

0 commit comments

Comments
 (0)