Skip to content

Commit 973a3db

Browse files
Merge remote-tracking branch 'origin/main' into PRMP-862
2 parents 0381fe8 + 340116a commit 973a3db

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+13624
-57
lines changed

.github/workflows/automated-sbom-repo-scan.yml renamed to .github/workflows/automated-pr-validator.yml

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
name: 'Z-AUTOMATED: SBOM Repo Scan'
1+
name: "Z-AUTOMATED: PR Validator"
22

33
on:
44
pull_request:
55
types: [opened, synchronize, reopened]
66

7-
permissions:
8-
actions: read # Required for anchore/sbom-action
9-
contents: write # Required for anchore/sbom-action
10-
id-token: write # Required for requesting the JWT
11-
pull-requests: write
12-
137
jobs:
148
sbom_scan:
159
name: SBOM Repo Scan
1610
runs-on: ubuntu-latest
11+
permissions:
12+
actions: read # Required for anchore/sbom-action
13+
contents: write # Required for anchore/sbom-action
14+
id-token: write # Required for requesting the JWT
15+
pull-requests: write
1716
steps:
18-
- uses: actions/checkout@v5
17+
- name: Checkout
18+
uses: actions/checkout@v5
1919
with:
20-
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
20+
fetch-depth: 0
2121

2222
- uses: anchore/sbom-action@v0
2323
with:
@@ -51,14 +51,14 @@ jobs:
5151
repo: context.repo.repo,
5252
issue_number: context.issue.number,
5353
})
54-
54+
5555
const botComment = comments.find(comment => {
5656
return comment.user.type === 'Bot' && comment.body.includes('Code security issues found')
5757
})
5858
5959
// 2. Prepare format of the comment
6060
const output = `### Code security issues found
61-
61+
6262
View full details [here](https://github.com/${{ github.repository }}/security/code-scanning?query=is%3Aopen+pr%3A${{ github.event.pull_request.number }}).`;
6363
6464
// 3. If we have a comment, update it, otherwise create a new one
@@ -70,7 +70,7 @@ jobs:
7070
body: output
7171
})
7272
}
73-
73+
7474
github.rest.issues.createComment({
7575
issue_number: context.issue.number,
7676
owner: context.repo.owner,
@@ -89,7 +89,7 @@ jobs:
8989
repo: context.repo.repo,
9090
issue_number: context.issue.number,
9191
})
92-
92+
9393
const botComment = comments.find(comment => {
9494
return comment.user.type === 'Bot' && comment.body.includes('Code security issues found')
9595
})
@@ -102,3 +102,21 @@ jobs:
102102
comment_id: botComment.id
103103
})
104104
}
105+
106+
markdown-validation:
107+
name: Markdown Validation
108+
runs-on: ubuntu-latest
109+
permissions:
110+
contents: read
111+
steps:
112+
- name: Checkout
113+
uses: actions/checkout@v6
114+
with:
115+
fetch-depth: 0
116+
117+
- name: Run Markdown Validation Script
118+
id: validate
119+
run: |
120+
BRANCH_NAME=${{ github.event.repository.default_branch }}
121+
chmod +x scripts/markdown-validator.sh
122+
scripts/markdown-validator.sh

.markdownlint.jsonc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"MD013": false,
3+
"MD033": false
4+
}

.terraform-docs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ sections:
1414

1515
content: |-
1616
{{ .Requirements }}
17+
1718
{{ .Resources }}
19+
1820
{{ .Inputs }}
21+
1922
{{ .Outputs }}
2023
2124
output:

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ This repository is used to build the infrastructure the NDR. That is it's sole p
88
- [Terraform docs](https://github.com/terraform-docs/terraform-docs)
99

1010
To install terraform-docs on WSL use the following commands (e.g. for v0.20.0):
11-
```
11+
12+
```shell
1213
curl -sSLo ./terraform-docs.tar.gz https://terraform-docs.io/dl/v0.20.0/terraform-docs-v0.20.0-$(uname)-amd64.tar.gz
1314
tar -xzf terraform-docs.tar.gz
1415
chmod +x terraform-docs
@@ -24,7 +25,7 @@ As this repository is a standalone infrastructure there is no python/node based
2425

2526
- Set this repository to get it's pre-commit hooks from .githooks
2627

27-
```
28+
```shell
2829
git config core.hooksPath .githooks
2930
```
3031

bootstrap/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Terraform Bootstrap
2+
13
## Requirements
24

35
| Name | Version |

infrastructure/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# National Document Repository - Infrastructure as Code
2+
13
## Requirements
24

35
| Name | Version |

infrastructure/api.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,15 @@ resource "aws_api_gateway_deployment" "ndr_api_deploy" {
7676
module.send-feedback-gateway,
7777
module.send-feedback-lambda,
7878
module.review_document_version_gateway,
79+
module.review_document_status_gateway,
80+
module.review-document-status-check-lambda,
7981
module.update-doc-ref-lambda,
8082
module.update-upload-state-gateway,
8183
module.update-upload-state-lambda,
8284
module.document-status-check-gateway,
8385
module.document-status-check-lambda,
8486
module.post-document-references-fhir-lambda,
87+
module.post_document_review_lambda,
8588
module.patch_document_review_lambda,
8689
module.virus_scan_result_gateway,
8790
module.virus_scan_result_lambda

infrastructure/dynamo_db.tf

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module "document_reference_dynamodb_table" {
22
source = "./modules/dynamo_db"
33
table_name = var.docstore_dynamodb_table_name
44
hash_key = "ID"
5-
deletion_protection_enabled = local.is_production
5+
deletion_protection_enabled = var.deletion_protection_enabled
66
stream_enabled = true
77
stream_view_type = "OLD_IMAGE"
88
ttl_enabled = true
@@ -45,7 +45,7 @@ module "cloudfront_edge_dynamodb_table" {
4545
source = "./modules/dynamo_db"
4646
table_name = var.cloudfront_edge_table_name
4747
hash_key = "ID"
48-
deletion_protection_enabled = local.is_production
48+
deletion_protection_enabled = var.deletion_protection_enabled
4949
stream_enabled = false
5050
ttl_enabled = true
5151
ttl_attribute_name = "TTL"
@@ -66,7 +66,7 @@ module "lloyd_george_reference_dynamodb_table" {
6666
source = "./modules/dynamo_db"
6767
table_name = var.lloyd_george_dynamodb_table_name
6868
hash_key = "ID"
69-
deletion_protection_enabled = local.is_production
69+
deletion_protection_enabled = var.deletion_protection_enabled
7070
stream_enabled = true
7171
stream_view_type = "OLD_IMAGE"
7272
ttl_enabled = true
@@ -127,7 +127,7 @@ module "unstitched_lloyd_george_reference_dynamodb_table" {
127127
source = "./modules/dynamo_db"
128128
table_name = var.unstitched_lloyd_george_dynamodb_table_name
129129
hash_key = "ID"
130-
deletion_protection_enabled = local.is_production
130+
deletion_protection_enabled = var.deletion_protection_enabled
131131
stream_enabled = true
132132
stream_view_type = "OLD_IMAGE"
133133
ttl_enabled = true
@@ -170,7 +170,7 @@ module "zip_store_reference_dynamodb_table" {
170170
source = "./modules/dynamo_db"
171171
table_name = var.zip_store_dynamodb_table_name
172172
hash_key = "ID"
173-
deletion_protection_enabled = local.is_production
173+
deletion_protection_enabled = var.deletion_protection_enabled
174174
stream_enabled = true
175175
ttl_enabled = false
176176

@@ -201,7 +201,7 @@ module "stitch_metadata_reference_dynamodb_table" {
201201
source = "./modules/dynamo_db"
202202
table_name = var.stitch_metadata_dynamodb_table_name
203203
hash_key = "ID"
204-
deletion_protection_enabled = local.is_production
204+
deletion_protection_enabled = var.deletion_protection_enabled
205205
stream_enabled = true
206206
ttl_enabled = true
207207
ttl_attribute_name = "ExpireAt"
@@ -233,7 +233,7 @@ module "auth_state_dynamodb_table" {
233233
source = "./modules/dynamo_db"
234234
table_name = var.auth_state_dynamodb_table_name
235235
hash_key = "State"
236-
deletion_protection_enabled = local.is_production
236+
deletion_protection_enabled = var.deletion_protection_enabled
237237
stream_enabled = false
238238
ttl_enabled = true
239239
ttl_attribute_name = "TimeToExist"
@@ -260,7 +260,7 @@ module "auth_session_dynamodb_table" {
260260
source = "./modules/dynamo_db"
261261
table_name = var.auth_session_dynamodb_table_name
262262
hash_key = "NDRSessionId"
263-
deletion_protection_enabled = local.is_production
263+
deletion_protection_enabled = var.deletion_protection_enabled
264264
stream_enabled = false
265265
ttl_enabled = true
266266
ttl_attribute_name = "TimeToExist"
@@ -287,7 +287,7 @@ module "bulk_upload_report_dynamodb_table" {
287287
source = "./modules/dynamo_db"
288288
table_name = var.bulk_upload_report_dynamodb_table_name
289289
hash_key = "ID"
290-
deletion_protection_enabled = local.is_production
290+
deletion_protection_enabled = var.deletion_protection_enabled
291291
stream_enabled = false
292292
ttl_enabled = false
293293
point_in_time_recovery_enabled = !local.is_sandbox
@@ -334,7 +334,7 @@ module "statistics_dynamodb_table" {
334334
table_name = var.statistics_dynamodb_table_name
335335
hash_key = "Date"
336336
sort_key = "StatisticID"
337-
deletion_protection_enabled = local.is_production
337+
deletion_protection_enabled = var.deletion_protection_enabled
338338
stream_enabled = false
339339
ttl_enabled = false
340340
point_in_time_recovery_enabled = !local.is_sandbox
@@ -372,7 +372,7 @@ module "access_audit_dynamodb_table" {
372372
table_name = var.access_audit_dynamodb_table_name
373373
hash_key = "Type"
374374
sort_key = "ID"
375-
deletion_protection_enabled = local.is_production
375+
deletion_protection_enabled = var.deletion_protection_enabled
376376
stream_enabled = false
377377
ttl_enabled = false
378378
point_in_time_recovery_enabled = !local.is_sandbox
@@ -426,7 +426,7 @@ module "pdm_dynamodb_table" {
426426
source = "./modules/dynamo_db"
427427
table_name = var.pdm_dynamodb_table_name
428428
hash_key = "ID"
429-
deletion_protection_enabled = local.is_production
429+
deletion_protection_enabled = var.deletion_protection_enabled
430430
stream_enabled = true
431431
stream_view_type = "OLD_IMAGE"
432432
ttl_enabled = true
@@ -494,12 +494,50 @@ module "pdm_dynamodb_table" {
494494
}
495495

496496

497+
module "core_dynamodb_table" {
498+
source = "./modules/dynamo_db"
499+
table_name = var.core_dynamodb_table_name
500+
hash_key = "NhsNumber"
501+
sort_key = "ID"
502+
deletion_protection_enabled = var.deletion_protection_enabled
503+
stream_enabled = true
504+
stream_view_type = "OLD_IMAGE"
505+
ttl_enabled = true
506+
ttl_attribute_name = "TTL"
507+
point_in_time_recovery_enabled = !local.is_sandbox
508+
attributes = [
509+
{
510+
name = "ID"
511+
type = "S"
512+
},
513+
{
514+
name = "NhsNumber"
515+
type = "S"
516+
},
517+
{
518+
name = "DocumentSnomedCodeType"
519+
type = "S"
520+
}
521+
]
522+
global_secondary_indexes = [
523+
{
524+
name = "idx_gsi_snomed_code"
525+
hash_key = "DocumentSnomedCodeType"
526+
range_key = "ID"
527+
projection_type = "ALL"
528+
}
529+
]
530+
environment = var.environment
531+
owner = var.owner
532+
}
533+
534+
497535
module "alarm_state_history_table" {
498536
source = "./modules/dynamo_db"
499537
table_name = var.alarm_state_history_table_name
500538
hash_key = "AlarmNameMetric"
501539
sort_key = "TimeCreated"
502-
deletion_protection_enabled = local.is_production
540+
deletion_protection_enabled = var.deletion_protection_enabled
503541
point_in_time_recovery_enabled = false
504542
stream_enabled = false
505543
ttl_enabled = true

infrastructure/gateway-review-document.tf

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module "review_document_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
5-
http_methods = ["GET"]
5+
http_methods = ["GET", "POST"]
66
authorization = "CUSTOM"
77
gateway_path = "DocumentReview"
88
authorizer_id = aws_api_gateway_authorizer.repo_authoriser.id
@@ -32,3 +32,15 @@ module "review_document_version_gateway" {
3232
"method.request.path.version" = true
3333
}
3434
}
35+
36+
module "review_document_status_gateway" {
37+
source = "./modules/gateway"
38+
api_gateway_id = aws_api_gateway_rest_api.ndr_doc_store_api.id
39+
parent_id = module.review_document_version_gateway.gateway_resource_id
40+
gateway_path = "Status"
41+
http_methods = ["GET"]
42+
require_credentials = true
43+
authorization = "CUSTOM"
44+
authorizer_id = aws_api_gateway_authorizer.repo_authoriser.id
45+
origin = contains(["prod"], terraform.workspace) ? "'https://${var.domain}'" : "'https://${terraform.workspace}.${var.domain}'"
46+
}

infrastructure/iam.tf

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,3 +317,41 @@ resource "aws_iam_role_policy_attachment" "get_doc_ref_presign_url" {
317317
role = aws_iam_role.get_doc_ref_presign_url_role.name
318318
policy_arn = aws_iam_policy.s3_document_data_policy_for_get_doc_ref_lambda.arn
319319
}
320+
321+
data "aws_iam_policy_document" "assume_role_policy_post_document_review_lambda" {
322+
statement {
323+
actions = ["sts:AssumeRole"]
324+
325+
principals {
326+
type = "AWS"
327+
identifiers = [module.post_document_review_lambda.lambda_execution_role_arn]
328+
}
329+
}
330+
}
331+
332+
resource "aws_iam_role" "post_document_review_presign" {
333+
name = "${terraform.workspace}_post_review_presign_url_role"
334+
assume_role_policy = data.aws_iam_policy_document.assume_role_policy_post_document_review_lambda.json
335+
}
336+
337+
resource "aws_iam_role_policy_attachment" "post_document_review" {
338+
role = aws_iam_role.post_document_review_presign.name
339+
policy_arn = aws_iam_policy.s3_document_data_policy_post_document_review_lambda.arn
340+
}
341+
342+
resource "aws_iam_policy" "s3_document_data_policy_post_document_review_lambda" {
343+
name = "${terraform.workspace}_put_document_only_policy_for_post_document_review_lambda"
344+
345+
policy = jsonencode({
346+
"Version" : "2012-10-17",
347+
"Statement" : [
348+
{
349+
"Effect" : "Allow",
350+
"Action" : [
351+
"s3:PutObject",
352+
],
353+
"Resource" : ["${module.ndr-bulk-staging-store.bucket_arn}/review/*"]
354+
}
355+
]
356+
})
357+
}

0 commit comments

Comments
 (0)