Skip to content

Commit c04adab

Browse files
NogaNHSrobg-nhs
andauthored
[NDR-97] Post document reference (#321)
* [NDR-96] initial commit, new lambda and endpoint * [NDR-97] Renaming current upload endpoint * [NDR-97] Renaming upload gateway endpoint * [NDR-97] changing doc ref gateway conf * [NDR-97] changing doc ref gateway conf * [NDR-97] name changes * [NDR-97] add env var * [NDR-97] line ending * [NDR-97] format * [NDR-97] fix name change * [NDR-97] missing permission * [NDR-97] missing iam role for pre-sign * [NDR-97] presign url iam policy * [NDR-97] move gateway doc ref to new file * [NDR-101] remove implicit depends on --------- Co-authored-by: robg-nhs <[email protected]>
1 parent 3e3af7c commit c04adab

File tree

11 files changed

+82
-62
lines changed

11 files changed

+82
-62
lines changed

infrastructure/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
| <a name="module_create-token-lambda"></a> [create-token-lambda](#module\_create-token-lambda) | ./modules/lambda | n/a |
5151
| <a name="module_create_doc_alarm"></a> [create\_doc\_alarm](#module\_create\_doc\_alarm) | ./modules/lambda_alarms | n/a |
5252
| <a name="module_create_doc_alarm_topic"></a> [create\_doc\_alarm\_topic](#module\_create\_doc\_alarm\_topic) | ./modules/sns | n/a |
53+
| <a name="module_create_document_reference_gateway"></a> [create\_document\_reference\_gateway](#module\_create\_document\_reference\_gateway) | ./modules/gateway | n/a |
5354
| <a name="module_create_token-alarm"></a> [create\_token-alarm](#module\_create\_token-alarm) | ./modules/lambda_alarms | n/a |
5455
| <a name="module_create_token-alarm_topic"></a> [create\_token-alarm\_topic](#module\_create\_token-alarm\_topic) | ./modules/sns | n/a |
5556
| <a name="module_data-collection-alarm"></a> [data-collection-alarm](#module\_data-collection-alarm) | ./modules/lambda_alarms | n/a |
@@ -128,6 +129,7 @@
128129
| <a name="module_pdf-stitching-alarm-topic"></a> [pdf-stitching-alarm-topic](#module\_pdf-stitching-alarm-topic) | ./modules/sns | n/a |
129130
| <a name="module_pdf-stitching-lambda"></a> [pdf-stitching-lambda](#module\_pdf-stitching-lambda) | ./modules/lambda | n/a |
130131
| <a name="module_pdf-stitching-lambda-alarms"></a> [pdf-stitching-lambda-alarms](#module\_pdf-stitching-lambda-alarms) | ./modules/lambda_alarms | n/a |
132+
| <a name="module_post-document-references-fhir-lambda"></a> [post-document-references-fhir-lambda](#module\_post-document-references-fhir-lambda) | ./modules/lambda | n/a |
131133
| <a name="module_pdm-document-store"></a> [pdm-document-store](#module\_pdm-document-store) | ./modules/s3/ | n/a |
132134
| <a name="module_pdm_dynamodb_table"></a> [pdm\_dynamodb\_table](#module\_pdm\_dynamodb\_table) | ./modules/dynamo_db | n/a |
133135
| <a name="module_route53_fargate_ui"></a> [route53\_fargate\_ui](#module\_route53\_fargate\_ui) | ./modules/route53 | n/a |
@@ -193,7 +195,6 @@
193195
| [aws_api_gateway_integration_response.get_document_reference_mock_403_response](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_integration_response) | resource |
194196
| [aws_api_gateway_integration_response.get_document_reference_mock_404_response](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_integration_response) | resource |
195197
| [aws_api_gateway_method.get_document_reference](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_method) | resource |
196-
| [aws_api_gateway_method.get_document_references_fhir](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_method) | resource |
197198
| [aws_api_gateway_method.login_proxy_method](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_method) | resource |
198199
| [aws_api_gateway_method.sandbox_get_document_reference](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_method) | resource |
199200
| [aws_api_gateway_method_response.response_200](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_method_response) | resource |

infrastructure/api.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ resource "aws_api_gateway_deployment" "ndr_api_deploy" {
4949
module.back_channel_logout_lambda,
5050
module.document_reference_gateway,
5151
module.create-doc-ref-lambda,
52+
module.create_document_reference_gateway,
5253
module.create-token-gateway,
5354
module.create-token-lambda,
5455
module.delete-doc-ref-gateway,
@@ -74,6 +75,7 @@ resource "aws_api_gateway_deployment" "ndr_api_deploy" {
7475
module.update-upload-state-lambda,
7576
module.upload_confirm_result_gateway,
7677
module.upload_confirm_result_lambda,
78+
module.post-document-references-fhir-lambda,
7779
module.virus_scan_result_gateway,
7880
module.virus_scan_result_lambda
7981
]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module "document_reference_gateway" {
2+
source = "./modules/gateway"
3+
api_gateway_id = aws_api_gateway_rest_api.ndr_doc_store_api.id
4+
parent_id = aws_api_gateway_rest_api.ndr_doc_store_api.root_resource_id
5+
http_methods = ["POST", "GET"]
6+
authorization = "NONE"
7+
api_key_required = true
8+
gateway_path = "DocumentReference"
9+
require_credentials = true
10+
}

infrastructure/iam.tf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ data "aws_iam_policy_document" "assume_role_policy_for_create_lambda" {
2020
actions = ["sts:AssumeRole"]
2121

2222
principals {
23-
type = "AWS"
24-
identifiers = [module.create-doc-ref-lambda.lambda_execution_role_arn]
23+
type = "AWS"
24+
identifiers = compact([
25+
module.create-doc-ref-lambda.lambda_execution_role_arn,
26+
local.is_production ? null : module.post-document-references-fhir-lambda[0].lambda_execution_role_arn
27+
])
28+
2529
}
2630
}
2731
}

infrastructure/lambda-create-doc-ref.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
module "document_reference_gateway" {
1+
module "create_document_reference_gateway" {
22
source = "./modules/gateway"
33
api_gateway_id = aws_api_gateway_rest_api.ndr_doc_store_api.id
44
parent_id = aws_api_gateway_rest_api.ndr_doc_store_api.root_resource_id
55
http_methods = ["POST"]
66
authorization = "CUSTOM"
7-
gateway_path = "DocumentReference"
7+
gateway_path = "CreateDocumentReference"
88
authorizer_id = aws_api_gateway_authorizer.repo_authoriser.id
99
require_credentials = true
1010
origin = contains(["prod"], terraform.workspace) ? "'https://${var.domain}'" : "'https://${terraform.workspace}.${var.domain}'"
@@ -73,7 +73,7 @@ module "create-doc-ref-lambda" {
7373
module.ndr-app-config.app_config_policy,
7474
]
7575
rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id
76-
resource_id = module.document_reference_gateway.gateway_resource_id
76+
resource_id = module.create_document_reference_gateway.gateway_resource_id
7777
http_methods = ["POST"]
7878
memory_size = 512
7979

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module "post-document-references-fhir-lambda" {
2+
count = local.is_production ? 0 : 1
3+
source = "./modules/lambda"
4+
name = "PostDocumentReferencesFHIR"
5+
handler = "handlers.post_fhir_document_reference_handler.lambda_handler"
6+
iam_role_policy_documents = [
7+
module.document_reference_dynamodb_table.dynamodb_write_policy_document,
8+
module.lloyd_george_reference_dynamodb_table.dynamodb_write_policy_document,
9+
module.ndr-bulk-staging-store.s3_write_policy_document,
10+
module.ndr-app-config.app_config_policy,
11+
aws_iam_policy.ssm_access_policy.policy
12+
]
13+
rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id
14+
resource_id = module.document_reference_gateway.gateway_resource_id
15+
http_methods = ["POST"]
16+
api_execution_arn = aws_api_gateway_rest_api.ndr_doc_store_api.execution_arn
17+
lambda_environment_variables = {
18+
APPCONFIG_APPLICATION = module.ndr-app-config.app_config_application_id
19+
APPCONFIG_ENVIRONMENT = module.ndr-app-config.app_config_environment_id
20+
APPCONFIG_CONFIGURATION = module.ndr-app-config.app_config_configuration_profile_id
21+
DOCUMENT_STORE_DYNAMODB_NAME = "${terraform.workspace}_${var.docstore_dynamodb_table_name}"
22+
LLOYD_GEORGE_DYNAMODB_NAME = "${terraform.workspace}_${var.lloyd_george_dynamodb_table_name}"
23+
STAGING_STORE_BUCKET_NAME = "${terraform.workspace}-${var.staging_store_bucket_name}"
24+
DOCUMENT_RETRIEVE_ENDPOINT_APIM = "${local.apim_api_url}/DocumentReference"
25+
PDS_FHIR_IS_STUBBED = local.is_sandbox
26+
WORKSPACE = terraform.workspace
27+
PRESIGNED_ASSUME_ROLE = aws_iam_role.create_post_presign_url_role.arn
28+
}
29+
}

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
resource "aws_api_gateway_method" "get_document_references_fhir" {
2-
count = local.is_production ? 0 : 1
3-
rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id
4-
resource_id = module.document_reference_gateway.gateway_resource_id
5-
http_method = "GET"
6-
authorization = "NONE"
7-
api_key_required = true
8-
}
9-
10-
111
module "search-document-references-fhir-lambda" {
122
count = local.is_production ? 0 : 1
133
source = "./modules/lambda"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
output "gateway_resource_id" {
2-
value = aws_api_gateway_resource.gateway_resource.id
1+
output "gateway_resource_id" {
2+
value = aws_api_gateway_resource.gateway_resource.id
33
}

infrastructure/modules/gateway/variable.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ variable "require_credentials" {
3030
}
3131

3232
variable "origin" {
33-
type = string
33+
type = string
34+
default = "'*'"
3435
}
3536

3637
variable "api_key_required" {
Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
output "invoke_arn" {
2-
value = aws_lambda_function.lambda.invoke_arn
3-
}
4-
5-
output "qualified_arn" {
6-
value = aws_lambda_function.lambda.qualified_arn
7-
}
8-
9-
output "function_name" {
10-
value = aws_lambda_function.lambda.function_name
11-
}
12-
13-
output "timeout" {
14-
value = aws_lambda_function.lambda.timeout
15-
}
16-
17-
output "lambda_arn" {
18-
value = aws_lambda_function.lambda.arn
19-
}
20-
21-
output "lambda_execution_role_name" {
22-
value = aws_iam_role.lambda_execution_role.name
23-
}
24-
25-
output "lambda_execution_role_arn" {
26-
value = aws_iam_role.lambda_execution_role.arn
1+
output "invoke_arn" {
2+
value = aws_lambda_function.lambda.invoke_arn
3+
}
4+
5+
output "qualified_arn" {
6+
value = aws_lambda_function.lambda.qualified_arn
7+
}
8+
9+
output "function_name" {
10+
value = aws_lambda_function.lambda.function_name
11+
}
12+
13+
output "timeout" {
14+
value = aws_lambda_function.lambda.timeout
15+
}
16+
17+
output "lambda_arn" {
18+
value = aws_lambda_function.lambda.arn
19+
}
20+
21+
output "lambda_execution_role_name" {
22+
value = aws_iam_role.lambda_execution_role.name
23+
}
24+
25+
output "lambda_execution_role_arn" {
26+
value = aws_iam_role.lambda_execution_role.arn
2727
}

0 commit comments

Comments
 (0)