Skip to content

Commit 479d49e

Browse files
authored
Merge branch 'main' into PRMP-1707
2 parents 62d8a51 + 6839bc3 commit 479d49e

File tree

3 files changed

+85
-1
lines changed

3 files changed

+85
-1
lines changed

infrastructure/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@
117117
| <a name="module_ndr-lloyd-george-store"></a> [ndr-lloyd-george-store](#module\_ndr-lloyd-george-store) | ./modules/s3/ | n/a |
118118
| <a name="module_ndr-vpc-ui"></a> [ndr-vpc-ui](#module\_ndr-vpc-ui) | ./modules/vpc/ | n/a |
119119
| <a name="module_ndr-zip-request-store"></a> [ndr-zip-request-store](#module\_ndr-zip-request-store) | ./modules/s3/ | n/a |
120+
| <a name="module_nhs-oauth-token-generator-alarm"></a> [nhs-oauth-token-generator-alarm](#module\_nhs-oauth-token-generator-alarm) | ./modules/lambda_alarms | n/a |
121+
| <a name="module_nhs-oauth-token-generator-alarm-topic"></a> [nhs-oauth-token-generator-alarm-topic](#module\_nhs-oauth-token-generator-alarm-topic) | ./modules/sns | n/a |
122+
| <a name="module_nhs-oauth-token-generator-lambda"></a> [nhs-oauth-token-generator-lambda](#module\_nhs-oauth-token-generator-lambda) | ./modules/lambda | n/a |
120123
| <a name="module_nrl-dlq-alarm-topic"></a> [nrl-dlq-alarm-topic](#module\_nrl-dlq-alarm-topic) | ./modules/sns | n/a |
121124
| <a name="module_pdf-stitching-alarm-topic"></a> [pdf-stitching-alarm-topic](#module\_pdf-stitching-alarm-topic) | ./modules/sns | n/a |
122125
| <a name="module_pdf-stitching-lambda"></a> [pdf-stitching-lambda](#module\_pdf-stitching-lambda) | ./modules/lambda | n/a |
@@ -204,10 +207,12 @@
204207
| [aws_cloudwatch_event_rule.bulk_upload_metadata_schedule](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_rule) | resource |
205208
| [aws_cloudwatch_event_rule.bulk_upload_report_schedule](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_rule) | resource |
206209
| [aws_cloudwatch_event_rule.data_collection_schedule](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_rule) | resource |
210+
| [aws_cloudwatch_event_rule.nhs_oauth_token_generator_schedule](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_rule) | resource |
207211
| [aws_cloudwatch_event_rule.statistical_report_schedule](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_rule) | resource |
208212
| [aws_cloudwatch_event_target.bulk_upload_metadata_schedule_event](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_target) | resource |
209213
| [aws_cloudwatch_event_target.bulk_upload_report_schedule_event](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_target) | resource |
210214
| [aws_cloudwatch_event_target.data_collection_schedule_event](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_target) | resource |
215+
| [aws_cloudwatch_event_target.nhs_oauth_token_generator_schedule](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_target) | resource |
211216
| [aws_cloudwatch_event_target.statistical_report_schedule_event](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_target) | resource |
212217
| [aws_cloudwatch_log_metric_filter.edge_presign_error](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_metric_filter) | resource |
213218
| [aws_cloudwatch_metric_alarm.api_gateway_alarm_4XX](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_metric_alarm) | resource |
@@ -293,6 +298,7 @@
293298
| [aws_lambda_permission.bulk_upload_metadata_schedule_permission](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_permission) | resource |
294299
| [aws_lambda_permission.bulk_upload_report_schedule_permission](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_permission) | resource |
295300
| [aws_lambda_permission.data_collection_schedule_permission](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_permission) | resource |
301+
| [aws_lambda_permission.nhs_oauth_token_generator_schedule](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_permission) | resource |
296302
| [aws_lambda_permission.statistical_report_schedule_permission](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_permission) | resource |
297303
| [aws_rum_app_monitor.ndr](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/rum_app_monitor) | resource |
298304
| [aws_s3_bucket.access_logs](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource |
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
module "nhs-oauth-token-generator-lambda" {
2+
source = "./modules/lambda"
3+
name = "NhsOauthTokenGeneratorLambda"
4+
handler = "handlers.nhs_oauth_token_generator_handler.lambda_handler"
5+
lambda_timeout = 120
6+
iam_role_policy_documents = [
7+
aws_iam_policy.ssm_access_policy.policy,
8+
module.ndr-app-config.app_config_policy
9+
]
10+
11+
rest_api_id = null
12+
api_execution_arn = null
13+
14+
lambda_environment_variables = {
15+
WORKSPACE = terraform.workspace
16+
}
17+
is_gateway_integration_needed = false
18+
is_invoked_from_gateway = false
19+
}
20+
21+
module "nhs-oauth-token-generator-alarm" {
22+
source = "./modules/lambda_alarms"
23+
lambda_function_name = module.nhs-oauth-token-generator-lambda.function_name
24+
lambda_timeout = module.nhs-oauth-token-generator-lambda.timeout
25+
lambda_name = "nhs_oauth_token_generator_handler"
26+
namespace = "AWS/Lambda"
27+
alarm_actions = [module.nhs-oauth-token-generator-alarm-topic.arn]
28+
ok_actions = [module.nhs-oauth-token-generator-alarm-topic.arn]
29+
}
30+
31+
module "nhs-oauth-token-generator-alarm-topic" {
32+
source = "./modules/sns"
33+
sns_encryption_key_id = module.sns_encryption_key.id
34+
current_account_id = data.aws_caller_identity.current.account_id
35+
topic_name = "nhs-oauth-token-generator-topic"
36+
topic_protocol = "lambda"
37+
topic_endpoint = module.nhs-oauth-token-generator-lambda.lambda_arn
38+
delivery_policy = jsonencode({
39+
"Version" : "2012-10-17",
40+
"Statement" : [
41+
{
42+
"Effect" : "Allow",
43+
"Principal" : {
44+
"Service" : "cloudwatch.amazonaws.com"
45+
},
46+
"Action" : [
47+
"SNS:Publish",
48+
],
49+
"Condition" : {
50+
"ArnLike" : {
51+
"aws:SourceArn" : "arn:aws:cloudwatch:eu-west-2:${data.aws_caller_identity.current.account_id}:alarm:*"
52+
}
53+
}
54+
"Resource" : "*"
55+
}
56+
]
57+
})
58+
}

infrastructure/schedules.tf

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,24 @@ resource "aws_iam_role_policy_attachment" "ods_weekly_update_ecs_execution" {
164164
count = local.is_sandbox ? 0 : 1
165165
role = aws_iam_role.ods_weekly_update_ecs_execution[0].name
166166
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceEventsRole"
167-
}
167+
}
168+
169+
resource "aws_cloudwatch_event_rule" "nhs_oauth_token_generator_schedule" {
170+
name = "${terraform.workspace}_nhs_oauth_token_generator_schedule"
171+
description = "Schedule for NHS OAuth Token Generator Lambda"
172+
schedule_expression = "rate(9 minutes)"
173+
}
174+
175+
resource "aws_cloudwatch_event_target" "nhs_oauth_token_generator_schedule" {
176+
rule = aws_cloudwatch_event_rule.nhs_oauth_token_generator_schedule.name
177+
target_id = "nhs_oauth_token_generator_schedule"
178+
arn = module.nhs-oauth-token-generator-lambda.lambda_arn
179+
}
180+
181+
resource "aws_lambda_permission" "nhs_oauth_token_generator_schedule" {
182+
statement_id = "AllowExecutionFromCloudWatch"
183+
action = "lambda:InvokeFunction"
184+
function_name = module.nhs-oauth-token-generator-lambda.function_name
185+
principal = "events.amazonaws.com"
186+
source_arn = aws_cloudwatch_event_rule.nhs_oauth_token_generator_schedule.arn
187+
}

0 commit comments

Comments
 (0)