Skip to content

Commit 477e409

Browse files
authored
Revert "[NDR-205] Remove "count = 1" from any resources that have it. (#400)"
This reverts commit 53ac709.
1 parent a3302bd commit 477e409

9 files changed

+53
-96
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module "fhir_document_reference_gateway" {
2+
count = 1
23
source = "./modules/gateway"
34
api_gateway_id = aws_api_gateway_rest_api.ndr_doc_store_api.id
45
parent_id = aws_api_gateway_rest_api.ndr_doc_store_api.root_resource_id
@@ -7,5 +8,4 @@ module "fhir_document_reference_gateway" {
78
api_key_required = true
89
gateway_path = "FhirDocumentReference"
910
require_credentials = true
10-
}
11-
11+
}

infrastructure/iam.tf

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ data "aws_iam_policy_document" "assume_role_policy_for_create_lambda" {
2323
type = "AWS"
2424
identifiers = compact([
2525
module.create-doc-ref-lambda.lambda_execution_role_arn,
26-
local.is_production ? null : module.post-document-references-fhir-lambda.lambda_execution_role_arn
26+
local.is_production ? null : module.post-document-references-fhir-lambda[0].lambda_execution_role_arn
2727
])
2828
}
2929
}
@@ -135,24 +135,27 @@ resource "aws_iam_policy" "s3_document_data_policy_for_get_doc_ref_lambda" {
135135
}
136136

137137
data "aws_iam_policy_document" "assume_role_policy_for_get_doc_ref_lambda" {
138+
count = 1
138139
statement {
139140
actions = ["sts:AssumeRole"]
140141

141142
principals {
142143
type = "AWS"
143-
identifiers = [module.get-doc-fhir-lambda.lambda_execution_role_arn]
144+
identifiers = [module.get-doc-fhir-lambda[0].lambda_execution_role_arn]
144145
}
145146
}
146147
}
147148

148149
resource "aws_iam_role" "get_fhir_doc_presign_url_role" {
150+
count = 1
149151
name = "${terraform.workspace}_get_fhir_doc_presign_url_role"
150-
assume_role_policy = data.aws_iam_policy_document.assume_role_policy_for_get_doc_ref_lambda.json
152+
assume_role_policy = data.aws_iam_policy_document.assume_role_policy_for_get_doc_ref_lambda[0].json
151153
}
152154

153155

154156
resource "aws_iam_role_policy_attachment" "get_doc_presign_url" {
155-
role = aws_iam_role.get_fhir_doc_presign_url_role.name
157+
count = 1
158+
role = aws_iam_role.get_fhir_doc_presign_url_role[0].name
156159
policy_arn = aws_iam_policy.s3_document_data_policy_for_get_doc_ref_lambda.arn
157160
}
158161

infrastructure/lambda-document-upload-check.tf

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module "document_upload_check_lambda" {
2+
count = 1
23
source = "./modules/lambda"
34
name = "DocumentReferenceVirusScanCheck"
45
handler = "handlers.document_reference_virus_scan_handler.lambda_handler"
@@ -48,18 +49,20 @@ data "aws_security_groups" "virus_scanner_api" {
4849
}
4950

5051
resource "aws_s3_bucket_notification" "document_upload_check_lambda_trigger" {
52+
count = 1
5153
bucket = module.ndr-bulk-staging-store.bucket_id
5254
lambda_function {
53-
lambda_function_arn = module.document_upload_check_lambda.lambda_arn
55+
lambda_function_arn = module.document_upload_check_lambda[0].lambda_arn
5456
events = ["s3:ObjectCreated:*"]
5557
filter_prefix = "user_upload"
5658
}
5759
}
5860

5961
resource "aws_lambda_permission" "document_upload_check_lambda" {
62+
count = 1
6063
statement_id = "AllowS3Invoke"
6164
action = "lambda:InvokeFunction"
62-
function_name = module.document_upload_check_lambda.function_name
65+
function_name = module.document_upload_check_lambda[0].function_name
6366
principal = "s3.amazonaws.com"
6467
source_arn = "arn:aws:s3:::${module.ndr-bulk-staging-store.bucket_id}"
6568
}

infrastructure/lambda-get-document-fhir.tf

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
resource "aws_api_gateway_resource" "get_document_reference" {
2+
count = 1
23
rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id
3-
parent_id = module.fhir_document_reference_gateway.gateway_resource_id
4+
parent_id = module.fhir_document_reference_gateway[0].gateway_resource_id
45
path_part = "{id}"
56
}
67

78
resource "aws_api_gateway_method" "get_document_reference" {
9+
count = 1
810
rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id
9-
resource_id = aws_api_gateway_resource.get_document_reference.id
11+
resource_id = aws_api_gateway_resource.get_document_reference[0].id
1012
http_method = "GET"
1113
authorization = "NONE"
1214
api_key_required = true
@@ -17,6 +19,7 @@ resource "aws_api_gateway_method" "get_document_reference" {
1719

1820

1921
module "get-doc-fhir-lambda" {
22+
count = 1
2023
source = "./modules/lambda"
2124
name = "GetDocumentReference"
2225
handler = "handlers.get_fhir_document_reference_handler.lambda_handler"
@@ -28,7 +31,7 @@ module "get-doc-fhir-lambda" {
2831
]
2932
kms_deletion_window = var.kms_deletion_window
3033
rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id
31-
resource_id = aws_api_gateway_resource.get_document_reference.id
34+
resource_id = aws_api_gateway_resource.get_document_reference[0].id
3235
http_methods = ["GET"]
3336
api_execution_arn = aws_api_gateway_rest_api.ndr_doc_store_api.execution_arn
3437
lambda_environment_variables = {
@@ -37,7 +40,7 @@ module "get-doc-fhir-lambda" {
3740
APPCONFIG_CONFIGURATION = module.ndr-app-config.app_config_configuration_profile_id
3841
WORKSPACE = terraform.workspace
3942
ENVIRONMENT = var.environment
40-
PRESIGNED_ASSUME_ROLE = aws_iam_role.get_fhir_doc_presign_url_role.arn
43+
PRESIGNED_ASSUME_ROLE = aws_iam_role.get_fhir_doc_presign_url_role[0].arn
4144
LLOYD_GEORGE_DYNAMODB_NAME = "${terraform.workspace}_${var.lloyd_george_dynamodb_table_name}"
4245
OIDC_CALLBACK_URL = contains(["prod"], terraform.workspace) ? "https://${var.domain}/auth-callback" : "https://${terraform.workspace}.${var.domain}/auth-callback"
4346
CLOUDFRONT_URL = module.cloudfront-distribution-lg.cloudfront_url

infrastructure/lambda-mns-notification.tf

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
module "mns-notification-lambda" {
2+
count = 1
23
source = "./modules/lambda"
34
name = "MNSNotificationLambda"
45
handler = "handlers.mns_notification_handler.lambda_handler"
56
iam_role_policy_documents = [
6-
module.sqs-mns-notification-queue.sqs_read_policy_document,
7-
module.sqs-mns-notification-queue.sqs_write_policy_document,
7+
module.sqs-mns-notification-queue[0].sqs_read_policy_document,
8+
module.sqs-mns-notification-queue[0].sqs_write_policy_document,
89
module.lloyd_george_reference_dynamodb_table.dynamodb_write_policy_document,
910
module.lloyd_george_reference_dynamodb_table.dynamodb_read_policy_document,
1011
aws_iam_policy.ssm_access_policy.policy,
1112
module.ndr-app-config.app_config_policy,
12-
aws_iam_policy.kms_mns_lambda_access.policy,
13+
aws_iam_policy.kms_mns_lambda_access[0].policy,
1314
]
1415
kms_deletion_window = var.kms_deletion_window
1516
rest_api_id = null
@@ -20,7 +21,7 @@ module "mns-notification-lambda" {
2021
APPCONFIG_CONFIGURATION = module.ndr-app-config.app_config_configuration_profile_id
2122
WORKSPACE = terraform.workspace
2223
LLOYD_GEORGE_DYNAMODB_NAME = "${terraform.workspace}_${var.lloyd_george_dynamodb_table_name}"
23-
MNS_NOTIFICATION_QUEUE_URL = module.sqs-mns-notification-queue.sqs_url
24+
MNS_NOTIFICATION_QUEUE_URL = module.sqs-mns-notification-queue[0].sqs_url
2425
PDS_FHIR_IS_STUBBED = local.is_sandbox
2526
}
2627
is_gateway_integration_needed = false
@@ -29,26 +30,29 @@ module "mns-notification-lambda" {
2930
}
3031

3132
resource "aws_lambda_event_source_mapping" "mns_notification_lambda" {
32-
event_source_arn = module.sqs-mns-notification-queue.endpoint
33-
function_name = module.mns-notification-lambda.lambda_arn
33+
count = 1
34+
event_source_arn = module.sqs-mns-notification-queue[0].endpoint
35+
function_name = module.mns-notification-lambda[0].lambda_arn
3436
}
3537

3638
module "mns-notification-alarm" {
39+
count = 1
3740
source = "./modules/lambda_alarms"
38-
lambda_function_name = module.mns-notification-lambda.function_name
39-
lambda_timeout = module.mns-notification-lambda.timeout
41+
lambda_function_name = module.mns-notification-lambda[0].function_name
42+
lambda_timeout = module.mns-notification-lambda[0].timeout
4043
lambda_name = "mns_notification_handler"
4144
namespace = "AWS/Lambda"
42-
alarm_actions = [module.mns-notification-alarm-topic.arn]
43-
ok_actions = [module.mns-notification-alarm-topic.arn]
45+
alarm_actions = [module.mns-notification-alarm-topic[0].arn]
46+
ok_actions = [module.mns-notification-alarm-topic[0].arn]
4447
}
4548

4649
module "mns-notification-alarm-topic" {
50+
count = 1
4751
source = "./modules/sns"
4852
sns_encryption_key_id = module.sns_encryption_key.id
4953
topic_name = "mns-notification-topic"
5054
topic_protocol = "lambda"
51-
topic_endpoint = module.mns-notification-lambda.lambda_arn
55+
topic_endpoint = module.mns-notification-lambda[0].lambda_arn
5256
delivery_policy = jsonencode({
5357
"Version" : "2012-10-17",
5458
"Statement" : [
@@ -72,6 +76,8 @@ module "mns-notification-alarm-topic" {
7276
}
7377

7478
resource "aws_iam_policy" "kms_mns_lambda_access" {
79+
count = 1
80+
7581
name = "${terraform.workspace}_mns_notification_lambda_access_policy"
7682
description = "KMS policy to allow lambda to read and write MNS SQS messages"
7783

@@ -84,7 +90,7 @@ resource "aws_iam_policy" "kms_mns_lambda_access" {
8490
"kms:GenerateDataKey"
8591
]
8692
Effect = "Allow"
87-
Resource = module.mns_encryption_key.kms_arn
93+
Resource = module.mns_encryption_key[0].kms_arn
8894
},
8995
]
9096
})

infrastructure/lambda-post-document-fhir.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module "post-document-references-fhir-lambda" {
2+
count = 1
23
source = "./modules/lambda"
34
name = "PostDocumentReferencesFHIR"
45
handler = "handlers.post_fhir_document_reference_handler.lambda_handler"
@@ -11,7 +12,7 @@ module "post-document-references-fhir-lambda" {
1112
]
1213
kms_deletion_window = var.kms_deletion_window
1314
rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id
14-
resource_id = module.fhir_document_reference_gateway.gateway_resource_id
15+
resource_id = module.fhir_document_reference_gateway[0].gateway_resource_id
1516
http_methods = ["POST"]
1617
api_execution_arn = aws_api_gateway_rest_api.ndr_doc_store_api.execution_arn
1718
lambda_environment_variables = {

infrastructure/lambda-search-document-references-fhir.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module "search-document-references-fhir-lambda" {
2+
count = 1
23
source = "./modules/lambda"
34
name = "SearchDocumentReferencesFHIR"
45
handler = "handlers.fhir_document_reference_search_handler.lambda_handler"
@@ -13,7 +14,7 @@ module "search-document-references-fhir-lambda" {
1314
]
1415
kms_deletion_window = var.kms_deletion_window
1516
rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id
16-
resource_id = module.fhir_document_reference_gateway.gateway_resource_id
17+
resource_id = module.fhir_document_reference_gateway[0].gateway_resource_id
1718
http_methods = ["GET"]
1819
api_execution_arn = aws_api_gateway_rest_api.ndr_doc_store_api.execution_arn
1920
lambda_environment_variables = {

infrastructure/mns.tf

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ data "aws_ssm_parameter" "mns_lambda_role" {
44

55

66
module "mns_encryption_key" {
7+
count = 1
78
source = "./modules/kms"
89
kms_key_name = "alias/mns-notification-encryption-key-kms-${terraform.workspace}"
910
kms_key_description = "Custom KMS Key to enable server side encryption for mns subscriptions"
@@ -16,6 +17,7 @@ module "mns_encryption_key" {
1617
}
1718

1819
module "sqs-mns-notification-queue" {
20+
count = 1
1921
source = "./modules/sqs"
2022
name = "mns-notification-queue"
2123
max_size_message = 256 * 1024 # allow message size up to 256 KB
@@ -25,14 +27,16 @@ module "sqs-mns-notification-queue" {
2527
max_visibility = 901
2628
delay = 60
2729
enable_sse = null
28-
kms_master_key_id = module.mns_encryption_key.id
30+
kms_master_key_id = module.mns_encryption_key[0].id
2931
enable_dlq = true
3032
dlq_visibility_timeout = 0
3133
max_receive_count = 3
3234
}
3335

3436
resource "aws_sqs_queue_policy" "mns_sqs_access" {
35-
queue_url = module.sqs-mns-notification-queue.sqs_url
37+
count = 1
38+
39+
queue_url = module.sqs-mns-notification-queue[0].sqs_url
3640

3741
policy = jsonencode({
3842
Version = "2012-10-17"
@@ -43,7 +47,7 @@ resource "aws_sqs_queue_policy" "mns_sqs_access" {
4347
AWS = data.aws_ssm_parameter.mns_lambda_role.value
4448
},
4549
Action = "SQS:SendMessage",
46-
Resource = module.sqs-mns-notification-queue.sqs_arn
50+
Resource = module.sqs-mns-notification-queue[0].sqs_arn
4751
}
4852
]
4953
})
@@ -62,7 +66,7 @@ resource "aws_cloudwatch_metric_alarm" "msn_dlq_new_message" {
6266
alarm_actions = [module.mns-dlq-alarm-topic.arn]
6367

6468
dimensions = {
65-
QueueName = module.sqs-mns-notification-queue.dlq_name
69+
QueueName = module.sqs-mns-notification-queue[0].dlq_name
6670
}
6771
}
6872

@@ -93,5 +97,5 @@ module "mns-dlq-alarm-topic" {
9397
}
9498
]
9599
})
96-
depends_on = [module.sqs-mns-notification-queue]
100+
depends_on = [module.sqs-mns-notification-queue[0]]
97101
}

infrastructure/moved-resources.tf

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -22,68 +22,4 @@ moved {
2222
moved {
2323
from = module.upload_confirm_result_alarm_topic
2424
to = module.document-status-check-alarm-topic
25-
}
26-
27-
#NDR-205
28-
29-
moved {
30-
from = module.fhir_document_reference_gateway[0]
31-
to = module.fhir_document_reference_gateway
32-
}
33-
34-
moved {
35-
from = module.post-document-references-fhir-lambda[0].aws_iam_role.lambda_execution_role
36-
to = module.post-document-references-fhir-lambda.aws_iam_role.lambda_execution_role
37-
}
38-
39-
moved {
40-
from = module.post-document-references-fhir-lambda[0].aws_cloudwatch_log_group.lambda_logs[0]
41-
to = module.post-document-references-fhir-lambda.aws_cloudwatch_log_group.lambda_logs[0]
42-
}
43-
44-
moved {
45-
from = module.post-document-references-fhir-lambda[0].aws_lambda_function.lambda
46-
to = module.post-document-references-fhir-lambda.aws_lambda_function.lambda
47-
}
48-
49-
moved {
50-
from = module.post-document-references-fhir-lambda[0].aws_kms_alias.lambda
51-
to = module.post-document-references-fhir-lambda.aws_kms_alias.lambda
52-
}
53-
moved {
54-
from = module.post-document-references-fhir-lambda[0].aws_iam_policy.combined_policies
55-
to = module.post-document-references-fhir-lambda.aws_iam_policy.combined_policies
56-
}
57-
58-
moved {
59-
from = module.post-document-references-fhir-lambda[0].aws_lambda_permission.lambda_permission[0]
60-
to = module.post-document-references-fhir-lambda.aws_lambda_permission.lambda_permission[0]
61-
}
62-
63-
moved {
64-
from = module.get-doc-fhir-lambda[0].aws_iam_role.lambda_execution_role
65-
to = module.get-doc-fhir-lambda.aws_iam_role.lambda_execution_role
66-
}
67-
68-
moved {
69-
from = module.get-doc-fhir-lambda[0].aws_cloudwatch_log_group.lambda_logs[0]
70-
to = module.get-doc-fhir-lambda.aws_cloudwatch_log_group.lambda_logs[0]
71-
}
72-
73-
moved {
74-
from = module.get-doc-fhir-lambda[0].aws_lambda_function.lambda
75-
to = module.get-doc-fhir-lambda.aws_lambda_function.lambda
76-
}
77-
moved {
78-
from = module.get-doc-fhir-lambda[0].aws_kms_alias.lambda
79-
to = module.get-doc-fhir-lambda.aws_kms_alias.lambda
80-
}
81-
moved {
82-
from = module.get-doc-fhir-lambda[0].aws_iam_policy.combined_policies
83-
to = module.get-doc-fhir-lambda.aws_iam_policy.combined_policies
84-
}
85-
86-
moved {
87-
from = module.get-doc-fhir-lambda[0].aws_lambda_permission.lambda_permission[0]
88-
to = module.get-doc-fhir-lambda.aws_lambda_permission.lambda_permission[0]
89-
}
25+
}

0 commit comments

Comments
 (0)