Skip to content

Commit 0797b64

Browse files
authored
Merge branch 'main' into PRMP-1469
2 parents 208c963 + b2bd3c4 commit 0797b64

19 files changed

+434
-50
lines changed
Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,57 @@
1-
# .github/workflows/terraform-dev
2-
name: 'Deploy and Version Main to Pre-Prod'
1+
name: 'Deploy to Pre-Prod'
32

43
on:
54
workflow_dispatch:
5+
inputs:
6+
branch_or_tag:
7+
description: "Which branch or tag do you want to deploy to pre-prod?"
8+
required: true
9+
type: string
10+
default: main
611

712
permissions:
813
pull-requests: write
914
id-token: write # This is required for requesting the JWT
1015
contents: read # This is required for actions/checkout
1116

1217
jobs:
13-
1418
tag_and_release:
1519
runs-on: ubuntu-latest
1620
outputs:
17-
tag: ${{steps.versioning.outputs.tag}}
18-
new_tag: ${{steps.versioning.outputs.new_tag}}
21+
version: ${{ steps.versioning.outputs.tag || github.event.inputs.branch_or_tag }}
1922
permissions: write-all
2023

2124
steps:
22-
23-
- uses: actions/checkout@v4
25+
- name: Checkout main
26+
if: ${{ github.event.inputs.branch_or_tag == 'main' }}
27+
uses: actions/checkout@v4
2428
with:
2529
ref: main
2630
fetch-depth: '0'
2731

2832
- name: Bump version and push tag
33+
if: ${{ github.event.inputs.branch_or_tag == 'main' }}
2934
id: versioning
3035
uses: anothrNick/[email protected]
3136
env:
3237
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3338
WITH_V: false
3439
DEFAULT_BUMP: patch
35-
40+
3641
- name: View outputs
3742
run: |
38-
echo Current tag: ${{steps.versioning.outputs.tag}}
39-
echo New tag: ${{steps.versioning.outputs.new_tag}}
43+
echo Deploying branch or tagged version to pre-prod: ${{ steps.versioning.outputs.tag || github.event.inputs.branch_or_tag }}
4044
4145
terraform_process:
4246
runs-on: ubuntu-latest
4347
needs: ['tag_and_release']
4448
environment: pre-prod
49+
4550
steps:
46-
# Checkout the repository to the GitHub Actions runner
4751
- name: Checkout
4852
uses: actions/checkout@v4
4953
with:
50-
ref: ${{needs.tag_and_release.outputs.tag}}
54+
ref: ${{needs.tag_and_release.outputs.version}}
5155
fetch-depth: '0'
5256

5357
- name: Configure AWS Credentials
@@ -57,11 +61,7 @@ jobs:
5761
role-skip-session-tagging: true
5862
aws-region: ${{ vars.AWS_REGION }}
5963
mask-aws-account-id: true
60-
61-
- name: View AWS Role
62-
run: aws sts get-caller-identity
6364

64-
# Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token
6565
- name: Setup Terraform
6666
uses: hashicorp/setup-terraform@v3
6767
with:
@@ -79,8 +79,7 @@ jobs:
7979
run: terraform workspace select ${{ secrets.AWS_WORKSPACE }}
8080
working-directory: ./infrastructure
8181
shell: bash
82-
83-
# Checks that all Terraform configuration files adhere to a canonical format
82+
8483
- name: Terraform Format
8584
run: terraform fmt -check
8685
working-directory: ./infrastructure
@@ -95,5 +94,3 @@ jobs:
9594
- name: Terraform Apply
9695
run: terraform apply -auto-approve -input=false tf.plan
9796
working-directory: ./infrastructure
98-
99-

infrastructure/README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
| Name | Version |
1010
|------|---------|
11-
| <a name="provider_aws"></a> [aws](#provider\_aws) | ~> 5.0 |
11+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.72.1 |
1212

1313
## Modules
1414

@@ -163,11 +163,24 @@
163163
| [aws_api_gateway_domain_name.custom_api_domain](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_domain_name) | resource |
164164
| [aws_api_gateway_gateway_response.bad_gateway_response](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_gateway_response) | resource |
165165
| [aws_api_gateway_gateway_response.unauthorised_response](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_gateway_response) | resource |
166+
| [aws_api_gateway_integration.get_document_reference_mock](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_integration) | resource |
167+
| [aws_api_gateway_integration_response.get_document_reference_mock_200_response](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_integration_response) | resource |
168+
| [aws_api_gateway_integration_response.get_document_reference_mock_401_response](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_integration_response) | resource |
169+
| [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 |
170+
| [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 |
166171
| [aws_api_gateway_method.get_document_reference](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_method) | resource |
167172
| [aws_api_gateway_method.login_proxy_method](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_method) | resource |
173+
| [aws_api_gateway_method.sandbox_get_document_reference](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_method) | resource |
174+
| [aws_api_gateway_method_response.response_200](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_method_response) | resource |
175+
| [aws_api_gateway_method_response.response_401](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_method_response) | resource |
176+
| [aws_api_gateway_method_response.response_403](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_method_response) | resource |
177+
| [aws_api_gateway_method_response.response_404](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_method_response) | resource |
168178
| [aws_api_gateway_resource.auth_resource](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_resource) | resource |
169179
| [aws_api_gateway_resource.get_document_reference](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_resource) | resource |
170180
| [aws_api_gateway_resource.login_resource](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_resource) | resource |
181+
| [aws_api_gateway_resource.nrl_sandbox](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_resource) | resource |
182+
| [aws_api_gateway_resource.sandbox_get_document_reference](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_resource) | resource |
183+
| [aws_api_gateway_resource.sandbox_get_document_reference_path_parameter](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_resource) | resource |
171184
| [aws_api_gateway_rest_api.ndr_doc_store_api](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_rest_api) | resource |
172185
| [aws_api_gateway_stage.ndr_api](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_stage) | resource |
173186
| [aws_api_gateway_usage_plan.apim](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_usage_plan) | resource |
@@ -186,10 +199,12 @@
186199
| [aws_cloudwatch_event_target.data_collection_schedule_event](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_target) | resource |
187200
| [aws_cloudwatch_event_target.statistical_report_schedule_event](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_target) | resource |
188201
| [aws_cloudwatch_log_group.mesh_log_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_group) | resource |
202+
| [aws_cloudwatch_log_metric_filter.edge_presign_error](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_metric_filter) | resource |
189203
| [aws_cloudwatch_log_metric_filter.error_log_metric_filter](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_metric_filter) | resource |
190204
| [aws_cloudwatch_log_metric_filter.inbox_message_count](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_metric_filter) | resource |
191205
| [aws_cloudwatch_metric_alarm.api_gateway_alarm_4XX](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_metric_alarm) | resource |
192206
| [aws_cloudwatch_metric_alarm.api_gateway_alarm_5XX](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_metric_alarm) | resource |
207+
| [aws_cloudwatch_metric_alarm.edge_presign_lambda_error](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_metric_alarm) | resource |
193208
| [aws_cloudwatch_metric_alarm.error_log_alarm](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_metric_alarm) | resource |
194209
| [aws_cloudwatch_metric_alarm.inbox-messages-not-consumed](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_metric_alarm) | resource |
195210
| [aws_cloudwatch_metric_alarm.nrl_dlq_new_messages](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_metric_alarm) | resource |
@@ -280,6 +295,8 @@
280295
| [aws_s3_bucket_lifecycle_configuration.lg-lifecycle-rules](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_lifecycle_configuration) | resource |
281296
| [aws_s3_bucket_lifecycle_configuration.staging-store-lifecycle-rules](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_lifecycle_configuration) | resource |
282297
| [aws_s3_bucket_policy.logs_bucket_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_policy) | resource |
298+
| [aws_s3_bucket_public_access_block.logs_bucket](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_public_access_block) | resource |
299+
| [aws_s3_bucket_versioning.logs_bucket](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_versioning) | resource |
283300
| [aws_scheduler_schedule.ods_weekly_update_ecs](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/scheduler_schedule) | resource |
284301
| [aws_security_group.ndr_mesh_sg](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group) | resource |
285302
| [aws_sns_topic.alarm_notifications_topic](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic) | resource |
@@ -306,6 +323,7 @@
306323
| [aws_iam_policy_document.ecs-assume-role-policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
307324
| [aws_iam_policy_document.ecs_execution](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
308325
| [aws_iam_policy_document.kms_policy_doc](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
326+
| [aws_iam_policy_document.logs_bucket_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
309327
| [aws_iam_policy_document.logs_policy_doc](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
310328
| [aws_iam_policy_document.sns_failure_feedback_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
311329
| [aws_iam_policy_document.sns_policy_doc](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |

infrastructure/api.tf

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ resource "aws_api_gateway_rest_api" "ndr_doc_store_api" {
1414
resource "aws_api_gateway_domain_name" "custom_api_domain" {
1515
domain_name = local.api_gateway_full_domain_name
1616
regional_certificate_arn = module.ndr-ecs-fargate-app.certificate_arn
17+
security_policy = "TLS_1_2"
1718

1819
endpoint_configuration {
1920
types = ["REGIONAL"]
@@ -40,6 +41,7 @@ resource "aws_api_gateway_deployment" "ndr_api_deploy" {
4041
triggers = {
4142
redeployment = sha1(jsonencode([
4243
aws_api_gateway_rest_api.ndr_doc_store_api.body,
44+
aws_api_gateway_authorizer.repo_authoriser,
4345
module.authoriser-lambda,
4446
module.back-channel-logout-gateway,
4547
module.back_channel_logout_lambda,
@@ -112,9 +114,10 @@ resource "aws_api_gateway_deployment" "ndr_api_deploy" {
112114
}
113115

114116
resource "aws_api_gateway_stage" "ndr_api" {
115-
deployment_id = aws_api_gateway_deployment.ndr_api_deploy.id
116-
rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id
117-
stage_name = var.environment
117+
deployment_id = aws_api_gateway_deployment.ndr_api_deploy.id
118+
rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id
119+
stage_name = var.environment
120+
xray_tracing_enabled = false
118121
}
119122

120123
resource "aws_api_gateway_gateway_response" "unauthorised_response" {

infrastructure/buckets.tf

Lines changed: 64 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -171,20 +171,70 @@ resource "aws_s3_bucket" "logs_bucket" {
171171
}
172172
}
173173

174-
resource "aws_s3_bucket_policy" "logs_bucket_policy" {
174+
resource "aws_s3_bucket_versioning" "logs_bucket" {
175+
count = local.is_production ? 1 : 0
176+
175177
bucket = aws_s3_bucket.logs_bucket.id
176-
policy = jsonencode({
177-
"Version" : "2012-10-17",
178-
"Statement" : [
179-
{
180-
"Principal" : {
181-
"AWS" : data.aws_elb_service_account.main.arn
182-
},
183-
"Action" : "s3:PutObject",
184-
"Resource" : "${aws_s3_bucket.logs_bucket.arn}/AWSLogs/${data.aws_caller_identity.current.account_id}/*"
185-
"Effect" : "Allow",
186-
}
178+
179+
versioning_configuration {
180+
status = "Enabled"
181+
}
182+
}
183+
184+
resource "aws_s3_bucket_public_access_block" "logs_bucket" {
185+
bucket = aws_s3_bucket.logs_bucket.id
186+
187+
block_public_acls = true
188+
block_public_policy = true
189+
ignore_public_acls = true
190+
restrict_public_buckets = true
191+
}
192+
193+
data "aws_iam_policy_document" "logs_bucket_policy" {
194+
statement {
195+
effect = "Deny"
196+
197+
principals {
198+
type = "*"
199+
identifiers = ["*"]
200+
}
201+
202+
actions = [
203+
"s3:*",
204+
]
205+
206+
resources = [
207+
"${aws_s3_bucket.logs_bucket.arn}/*",
187208
]
188-
})
189-
depends_on = [aws_s3_bucket.logs_bucket]
209+
210+
condition {
211+
test = "Bool"
212+
variable = "aws:SecureTransport"
213+
values = ["false"]
214+
}
215+
}
216+
217+
statement {
218+
effect = "Allow"
219+
220+
principals {
221+
type = "AWS"
222+
identifiers = [data.aws_elb_service_account.main.arn]
223+
}
224+
225+
actions = [
226+
"s3:PutObject",
227+
]
228+
229+
resources = [
230+
"${aws_s3_bucket.logs_bucket.arn}/AWSLogs/${data.aws_caller_identity.current.account_id}/*",
231+
]
232+
}
233+
}
234+
235+
resource "aws_s3_bucket_policy" "logs_bucket_policy" {
236+
bucket = aws_s3_bucket.logs_bucket.id
237+
policy = data.aws_iam_policy_document.logs_bucket_policy.json
190238
}
239+
240+

infrastructure/lambda-authoriser.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ module "authoriser-alarm-topic" {
7575

7676
resource "aws_api_gateway_authorizer" "repo_authoriser" {
7777
name = "${terraform.workspace}_repo_authoriser"
78-
type = "TOKEN"
78+
type = "REQUEST"
7979
identity_source = "method.request.header.Authorization"
8080
rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id
8181
authorizer_uri = module.authoriser-lambda.invoke_arn

infrastructure/lambda-edge-presign.tf

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,32 @@ module "edge_presign_alarm" {
99
depends_on = [module.edge-presign-lambda, module.edge_presign_alarm_topic]
1010
}
1111

12+
resource "aws_cloudwatch_log_metric_filter" "edge_presign_error" {
13+
name = "EdgePresignErrorFilter"
14+
pattern = "%LambdaError%"
15+
log_group_name = "/aws/lambda/us-east-1.${module.edge-presign-lambda.function_name}"
16+
metric_transformation {
17+
name = "EdgePresignErrorCount"
18+
namespace = "EdgeLambdaInsights"
19+
value = "1"
20+
}
21+
}
22+
23+
resource "aws_cloudwatch_metric_alarm" "edge_presign_lambda_error" {
24+
alarm_name = "${module.edge-presign-lambda.function_name}_error_alarm"
25+
metric_name = "EdgePresignErrorCount"
26+
namespace = "EdgeLambdaInsights"
27+
threshold = 0
28+
statistic = "Sum"
29+
period = "300"
30+
comparison_operator = "GreaterThanThreshold"
31+
evaluation_periods = "1"
32+
alarm_actions = [aws_sns_topic.alarm_notifications_topic[0].arn]
33+
ok_actions = [module.edge_presign_alarm_topic.arn]
34+
depends_on = [module.edge-presign-lambda, aws_sns_topic.alarm_notifications_topic[0]]
35+
alarm_description = "Triggers when Edge Presign Lambda errors."
36+
count = local.is_sandbox ? 0 : 1
37+
}
1238

1339
module "edge_presign_alarm_topic" {
1440
source = "./modules/sns"

infrastructure/lambda-search-patient.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ module "search-patient-details-lambda" {
6868
handler = "handlers.search_patient_details_handler.lambda_handler"
6969
iam_role_policy_documents = [
7070
aws_iam_policy.ssm_access_policy.policy,
71-
module.ndr-app-config.app_config_policy
71+
module.ndr-app-config.app_config_policy,
72+
module.auth_session_dynamodb_table.dynamodb_write_policy_document,
73+
module.auth_session_dynamodb_table.dynamodb_read_policy_document,
7274
]
7375
rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id
7476
resource_id = module.search-patient-details-gateway.gateway_resource_id
@@ -82,6 +84,7 @@ module "search-patient-details-lambda" {
8284
PDS_FHIR_IS_STUBBED = local.is_sandbox,
8385
SPLUNK_SQS_QUEUE_URL = try(module.sqs-splunk-queue[0].sqs_url, null)
8486
WORKSPACE = terraform.workspace
87+
AUTH_SESSION_TABLE_NAME = "${terraform.workspace}_${var.auth_session_dynamodb_table_name}"
8588
}
8689
api_execution_arn = aws_api_gateway_rest_api.ndr_doc_store_api.execution_arn
8790
depends_on = [

infrastructure/mesh-forwarder.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,9 @@ data "aws_iam_policy_document" "sns_failure_feedback_policy" {
392392

393393
# CloudWatch groups
394394
resource "aws_cloudwatch_log_group" "mesh_log_group" {
395-
count = local.is_mesh_forwarder_enable ? 1 : 0
396-
name = "/nhs/deductions/${terraform.workspace}/${var.mesh_component_name}"
395+
count = local.is_mesh_forwarder_enable ? 1 : 0
396+
name = "/nhs/deductions/${terraform.workspace}/${var.mesh_component_name}"
397+
retention_in_days = 0
397398

398399
tags = {
399400
Environment = var.environment

infrastructure/modules/ecs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ No modules.
6363
| <a name="input_ecs_task_definition_cpu"></a> [ecs\_task\_definition\_cpu](#input\_ecs\_task\_definition\_cpu) | n/a | `number` | `1024` | no |
6464
| <a name="input_ecs_task_definition_memory"></a> [ecs\_task\_definition\_memory](#input\_ecs\_task\_definition\_memory) | n/a | `number` | `2048` | no |
6565
| <a name="input_environment"></a> [environment](#input\_environment) | n/a | `string` | n/a | yes |
66-
| <a name="input_environment_vars"></a> [environment\_vars](#input\_environment\_vars) | n/a | `list` | <pre>[<br> null<br>]</pre> | no |
66+
| <a name="input_environment_vars"></a> [environment\_vars](#input\_environment\_vars) | n/a | `list` | <pre>[<br/> null<br/>]</pre> | no |
6767
| <a name="input_is_autoscaling_needed"></a> [is\_autoscaling\_needed](#input\_is\_autoscaling\_needed) | n/a | `bool` | `true` | no |
6868
| <a name="input_is_lb_needed"></a> [is\_lb\_needed](#input\_is\_lb\_needed) | n/a | `bool` | `false` | no |
6969
| <a name="input_is_service_needed"></a> [is\_service\_needed](#input\_is\_service\_needed) | n/a | `bool` | `true` | no |

infrastructure/modules/ecs/cluster.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ resource "aws_ecs_cluster" "ndr_ecs_cluster" {
1919
}
2020

2121
resource "aws_cloudwatch_log_group" "ecs_cluster_logs" {
22-
name = "${terraform.workspace}-${var.ecs_cluster_name}-logs"
22+
name = "${terraform.workspace}-${var.ecs_cluster_name}-logs"
23+
retention_in_days = 0
2324
}

0 commit comments

Comments
 (0)