Skip to content

Commit fa89052

Browse files
authored
PRMDR Build Process Fixes
* Changed the count in sqs instances to fix failing terraform * Attaching the security policy outside the lambda
1 parent f97f101 commit fa89052

File tree

9 files changed

+63
-39
lines changed

9 files changed

+63
-39
lines changed

infrastructure/audit.tf

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,27 @@ resource "aws_iam_role" "splunk_sqs_forwarder" {
2424
Version = "2012-10-17"
2525
Statement = [
2626
{
27-
effect = "Allow"
28-
actions = [
27+
Effect = "Allow"
28+
Action = [
2929
"sqs:GetQueueAttributes",
3030
"sqs:ListQueues",
3131
"sqs:ReceiveMessage",
3232
"sqs:GetQueueUrl",
3333
"sqs:SendMessage",
3434
"sqs:DeleteMessage"
3535
]
36-
resources = [
37-
module.sqs-splunk-queue.sqs_arn,
38-
module.sqs-nems-queue.sqs_arn
36+
Resource = [
37+
module.sqs-splunk-queue[0].sqs_arn,
38+
module.sqs-nems-queue[0].sqs_arn
3939
]
40-
}
40+
},
4141
]
4242
})
4343
}
4444
}
4545

4646
resource "aws_iam_policy" "lambda_audit_splunk_sqs_queue_send_policy" {
47+
count = local.is_sandbox ? 0 : 1
4748
policy = jsonencode({
4849
Version = "2012-10-17"
4950
Statement = [{
@@ -53,7 +54,7 @@ resource "aws_iam_policy" "lambda_audit_splunk_sqs_queue_send_policy" {
5354
"sqs:SendMessage",
5455
],
5556
"Resource" = [
56-
module.sqs-splunk-queue.sqs_arn
57+
module.sqs-splunk-queue[0].sqs_arn
5758
]
5859
}] })
5960
}

infrastructure/lambda-document-manifest-by-nhs-number.tf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ module "document-manifest-by-nhs-number-lambda" {
7272
module.ndr-lloyd-george-store.s3_object_access_policy,
7373
module.zip_store_reference_dynamodb_table.dynamodb_policy,
7474
module.ndr-zip-request-store.s3_object_access_policy,
75-
aws_iam_policy.lambda_audit_splunk_sqs_queue_send_policy.arn,
7675
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole",
7776
"arn:aws:iam::aws:policy/CloudWatchLambdaInsightsExecutionRolePolicy"
7877
]
@@ -87,11 +86,18 @@ module "document-manifest-by-nhs-number-lambda" {
8786
LLOYD_GEORGE_DYNAMODB_NAME = "${terraform.workspace}_${var.lloyd_george_dynamodb_table_name}"
8887
ZIPPED_STORE_BUCKET_NAME = "${terraform.workspace}-${var.zip_store_bucket_name}"
8988
ZIPPED_STORE_DYNAMODB_NAME = "${terraform.workspace}_${var.zip_store_dynamodb_table_name}"
90-
SPLUNK_SQS_QUEUE_URL = module.sqs-splunk-queue.sqs_url
89+
SPLUNK_SQS_QUEUE_URL = try(module.sqs-splunk-queue[0].sqs_url, null)
9190

9291
}
9392
depends_on = [
9493
aws_api_gateway_rest_api.ndr_doc_store_api,
9594
module.document-manifest-by-nhs-gateway,
95+
aws_iam_policy.lambda_audit_splunk_sqs_queue_send_policy[0]
9696
]
9797
}
98+
99+
resource "aws_iam_role_policy_attachment" "policy_manifest_lambda" {
100+
count = local.is_sandbox ? 0 : 1
101+
role = module.document-manifest-by-nhs-number-lambda.lambda_execution_role_name
102+
policy_arn = try(aws_iam_policy.lambda_audit_splunk_sqs_queue_send_policy[0].arn, null)
103+
}

infrastructure/lambda-lloyd-george-record-stitch.tf

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ module "lloyd-george-stitch-lambda" {
6969
module.ndr-lloyd-george-store.s3_object_access_policy,
7070
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole",
7171
"arn:aws:iam::aws:policy/CloudWatchLambdaInsightsExecutionRolePolicy",
72-
aws_iam_policy.lambda_audit_splunk_sqs_queue_send_policy.arn
7372
]
7473
rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id
7574
resource_id = module.lloyd-george-stitch-gateway.gateway_resource_id
@@ -78,12 +77,19 @@ module "lloyd-george-stitch-lambda" {
7877
lambda_environment_variables = {
7978
LLOYD_GEORGE_BUCKET_NAME = "${terraform.workspace}-${var.lloyd_george_bucket_name}"
8079
LLOYD_GEORGE_DYNAMODB_NAME = "${terraform.workspace}_${var.lloyd_george_dynamodb_table_name}"
81-
SPLUNK_SQS_QUEUE_URL = module.sqs-splunk-queue.sqs_url
80+
SPLUNK_SQS_QUEUE_URL = try(module.sqs-splunk-queue[0].sqs_url, null)
8281
}
8382
depends_on = [
8483
aws_api_gateway_rest_api.ndr_doc_store_api,
8584
module.ndr-lloyd-george-store,
8685
module.lloyd_george_reference_dynamodb_table,
87-
module.lloyd-george-stitch-gateway
86+
module.lloyd-george-stitch-gateway,
87+
aws_iam_policy.lambda_audit_splunk_sqs_queue_send_policy[0]
8888
]
8989
}
90+
91+
resource "aws_iam_role_policy_attachment" "lambda_stitch-lambda" {
92+
count = local.is_sandbox ? 0 : 1
93+
role = module.lloyd-george-stitch-lambda.lambda_execution_role_name
94+
policy_arn = try(aws_iam_policy.lambda_audit_splunk_sqs_queue_send_policy[0].arn, null)
95+
}

infrastructure/lambda-search-patient.tf

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,20 @@ module "search-patient-details-lambda" {
6767
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole",
6868
"arn:aws:iam::aws:policy/CloudWatchLambdaInsightsExecutionRolePolicy",
6969
aws_iam_policy.ssm_policy_pds.arn,
70-
aws_iam_policy.lambda_audit_splunk_sqs_queue_send_policy.arn
7170
]
7271
rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id
7372
resource_id = module.search-patient-details-gateway.gateway_resource_id
7473
http_method = "GET"
7574
lambda_environment_variables = {
7675
SSM_PARAM_JWT_TOKEN_PUBLIC_KEY = "jwt_token_public_key"
7776
PDS_FHIR_IS_STUBBED = local.is_sandbox,
78-
SPLUNK_SQS_QUEUE_URL = module.sqs-splunk-queue.sqs_url
77+
SPLUNK_SQS_QUEUE_URL = try(module.sqs-splunk-queue[0].sqs_url, null)
7978
}
8079
api_execution_arn = aws_api_gateway_rest_api.ndr_doc_store_api.execution_arn
8180
depends_on = [
8281
aws_api_gateway_rest_api.ndr_doc_store_api,
83-
module.search-patient-details-gateway
82+
module.search-patient-details-gateway,
83+
aws_iam_policy.lambda_audit_splunk_sqs_queue_send_policy[0]
8484
]
8585
}
8686

@@ -102,4 +102,10 @@ resource "aws_iam_policy" "ssm_policy_pds" {
102102
}
103103
]
104104
})
105+
}
106+
107+
resource "aws_iam_role_policy_attachment" "policy_audit_search-patient-details-lambda" {
108+
count = local.is_sandbox ? 0 : 1
109+
role = module.search-patient-details-lambda.lambda_execution_role_name
110+
policy_arn = try(aws_iam_policy.lambda_audit_splunk_sqs_queue_send_policy[0].arn, null)
105111
}

infrastructure/lambda-token.tf

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ module "create-token-lambda" {
2929
aws_iam_policy.ssm_policy_token.arn,
3030
module.auth_session_dynamodb_table.dynamodb_policy,
3131
module.auth_state_dynamodb_table.dynamodb_policy,
32-
aws_iam_policy.lambda_audit_splunk_sqs_queue_send_policy.arn
3332
]
34-
3533
rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id
3634
resource_id = module.token-gateway.gateway_resource_id
3735
http_method = "GET"
@@ -42,15 +40,16 @@ module "create-token-lambda" {
4240
OIDC_CALLBACK_URL = "https://${terraform.workspace}.${var.domain}/auth-callback"
4341
AUTH_STATE_TABLE_NAME = "${terraform.workspace}_${var.auth_state_dynamodb_table_name}"
4442
AUTH_SESSION_TABLE_NAME = "${terraform.workspace}_${var.auth_session_dynamodb_table_name}"
45-
SPLUNK_SQS_QUEUE_URL = module.sqs-splunk-queue.sqs_url
43+
SPLUNK_SQS_QUEUE_URL = try(module.sqs-splunk-queue[0].sqs_url, null)
4644

4745
}
4846
depends_on = [
4947
aws_api_gateway_rest_api.ndr_doc_store_api,
5048
aws_iam_policy.ssm_policy_token,
5149
module.auth_session_dynamodb_table,
5250
module.auth_state_dynamodb_table,
53-
module.token-gateway
51+
module.token-gateway,
52+
aws_iam_policy.lambda_audit_splunk_sqs_queue_send_policy[0]
5453
]
5554
memory_size = 256
5655
}
@@ -114,4 +113,10 @@ resource "aws_iam_policy" "ssm_policy_token" {
114113
}
115114
]
116115
})
116+
}
117+
118+
resource "aws_iam_role_policy_attachment" "policy_audit_token_lambda" {
119+
count = local.is_sandbox ? 0 : 1
120+
role = module.create-token-lambda.lambda_execution_role_name
121+
policy_arn = try(aws_iam_policy.lambda_audit_splunk_sqs_queue_send_policy[0].arn, null)
117122
}

infrastructure/modules/lambda/variable.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,8 @@ output "timeout" {
7474

7575
output "endpoint" {
7676
value = aws_lambda_function.lambda.arn
77+
}
78+
79+
output "lambda_execution_role_name" {
80+
value = aws_iam_role.lambda_execution_role.name
7781
}

infrastructure/modules/sqs/main.tf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
resource "aws_sqs_queue" "sqs_queue" {
2-
count = var.enable_in_sandbox ? 1 : 0
32
name = "${terraform.workspace}-${var.name}"
43
delay_seconds = var.delay
54
visibility_timeout_seconds = var.max_visibility
@@ -30,7 +29,7 @@ resource "aws_iam_policy" "sqs_queue_policy" {
3029
"sqs:GetQueueAttributes"
3130
],
3231
"Resource" = [
33-
aws_sqs_queue.sqs_queue[0].arn
32+
aws_sqs_queue.sqs_queue.arn
3433
]
3534
}] })
3635
}

infrastructure/modules/sqs/variable.tf

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ variable "name" {
22
type = string
33
}
44

5-
variable "enable_in_sandbox" {
6-
type = bool
7-
default = true
8-
}
95
variable "delay" {
106
description = "The time in seconds that the delivery of all messages in the queue will be delayed"
117
type = number
@@ -65,12 +61,12 @@ variable "owner" {
6561
}
6662

6763
output "endpoint" {
68-
value = aws_sqs_queue.sqs_queue[0].arn
64+
value = aws_sqs_queue.sqs_queue.arn
6965
description = "Same as sqs queue arn. For use when setting the queue as endpoint of sns topic"
7066
}
7167

7268
output "sqs_arn" {
73-
value = aws_sqs_queue.sqs_queue[0].arn
69+
value = aws_sqs_queue.sqs_queue.arn
7470
}
7571

7672
output "sqs_policy" {
@@ -79,5 +75,5 @@ output "sqs_policy" {
7975
}
8076

8177
output "sqs_url" {
82-
value = aws_sqs_queue.sqs_queue[0].url
78+
value = aws_sqs_queue.sqs_queue.url
8379
}

infrastructure/queues.tf

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
module "sqs-splunk-queue" {
2-
source = "./modules/sqs"
3-
name = "splunk-queue"
4-
enable_in_sandbox = !local.is_sandbox
5-
environment = var.environment
6-
owner = var.owner
2+
source = "./modules/sqs"
3+
name = "splunk-queue"
4+
count = local.is_sandbox ? 0 : 1
5+
environment = var.environment
6+
owner = var.owner
77
}
88

99
module "sqs-nems-queue" {
10-
source = "./modules/sqs"
11-
name = "nems-queue"
12-
enable_in_sandbox = !local.is_sandbox
13-
environment = var.environment
14-
owner = var.owner
10+
source = "./modules/sqs"
11+
name = "nems-queue"
12+
count = local.is_sandbox ? 0 : 1
13+
environment = var.environment
14+
owner = var.owner
1515
}
1616

1717
module "sqs-lg-bulk-upload-metadata-queue" {
@@ -33,10 +33,11 @@ module "sqs-lg-bulk-upload-invalid-queue" {
3333
}
3434

3535
module "sqs-nems-queue-topic" {
36+
count = local.is_sandbox ? 0 : 1
3637
source = "./modules/sns"
3738
topic_name = "nems-queue-topic"
3839
topic_protocol = "sqs"
39-
topic_endpoint = module.sqs-nems-queue.endpoint
40+
topic_endpoint = module.sqs-nems-queue[0].endpoint
4041
delivery_policy = jsonencode({
4142
"Version" : "2012-10-17",
4243
"Statement" : [

0 commit comments

Comments
 (0)