Skip to content

Commit aa6c082

Browse files
committed
NRL-693 move to account wide infra and put emails as secrets data source
1 parent df9b6ad commit aa6c082

File tree

11 files changed

+57
-38
lines changed

11 files changed

+57
-38
lines changed

terraform/infrastructure/cloudwatch.tf renamed to terraform/account-wide-infrastructure/dev/cloudwatch.tf

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
module "lambda_errors_sns_topic" {
2-
source = "./modules/sns"
3-
name = "nrlf_lambda_errors_topic"
4-
prefix = local.prefix
5-
}
6-
7-
module "lambda_errors_cloudwatch_metric_alarm" {
8-
source = "./modules/cloudwatch"
9-
name = "nrlf-lambda-errors"
10-
prefix = local.prefix
1+
module "lambda_errors_cloudwatch_metric_alarm_dev" {
2+
source = "./modules/lambda-errors-metric-alarm"
3+
name_prefix = "nhsd-nrlf--dev"
114

125
comparison_operator = "GreaterThanOrEqualToThreshold"
136
evaluation_periods = 1

terraform/infrastructure/modules/cloudwatch/cloudwatch.tf renamed to terraform/account-wide-infrastructure/modules/lambda-errors-metric-alarm/cloudwatch.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
resource "aws_cloudwatch_metric_alarm" "metric_alarm" {
22
count = var.create_metric_alarm ? 1 : 0
33

4-
alarm_name = "${var.prefix}--${var.name}"
4+
alarm_name = "${var.name_prefix}--lambda-errors-metric_alarm"
55
alarm_description = var.alarm_description
66
actions_enabled = var.actions_enabled
77

8-
alarm_actions = var.alarm_actions
8+
alarm_actions = [aws_sns_topic.sns_topic.arn]
99
ok_actions = var.ok_actions
1010
insufficient_data_actions = var.insufficient_data_actions
1111

terraform/infrastructure/modules/cloudwatch/output.tf renamed to terraform/account-wide-infrastructure/modules/lambda-errors-metric-alarm/output.tf

File renamed without changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
data "aws_secretsmanager_secret" "emails" {
2+
name = "${var.name_prefix}-emails"
3+
}
4+
5+
data "aws_secretsmanager_secret_version" "emails" {
6+
secret_id = data.aws_secretsmanager_secret.emails.id
7+
8+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
resource "aws_sns_topic" "sns_topic" {
2+
name = "${var.name_prefix}--lambda-errors-sns-topic"
3+
}
4+
5+
resource "aws_sns_topic_subscription" "sns_subscription" {
6+
for_each = toset(data.aws_secretsmanager_secret_version.emails.secret_string)
7+
topic_arn = aws_sns_topic.sns_topic.arn
8+
protocol = "email"
9+
endpoint = each.value
10+
}

terraform/infrastructure/modules/cloudwatch/vars.tf renamed to terraform/account-wide-infrastructure/modules/lambda-errors-metric-alarm/vars.tf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ variable "tags" {
128128
default = {}
129129
}
130130

131-
variable "prefix" {}
132-
133-
variable "name" {}
131+
variable "name_prefix" {
132+
type = string
133+
description = "The prefix to apply to all resources in the module."
134+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module "lambda_errors_cloudwatch_metric_alarm_dev" {
2+
source = "./modules/lambda-errors-metric-alarm"
3+
name_prefix = "nhsd-nrlf--prod"
4+
5+
comparison_operator = "GreaterThanOrEqualToThreshold"
6+
evaluation_periods = 1
7+
metric_name = "Errors"
8+
namespace = "AWS/Lambda"
9+
period = 60
10+
statistic = "Maximum"
11+
threshold = 1
12+
unit = "Count"
13+
alarm_description = "This metric monitors the number of Lambda errors that have occurred"
14+
alarm_actions = [module.lambda_errors_sns_topic.sns_topic_arn]
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module "lambda_errors_cloudwatch_metric_alarm_dev" {
2+
source = "./modules/lambda-errors-metric-alarm"
3+
name_prefix = "nhsd-nrlf--test"
4+
5+
comparison_operator = "GreaterThanOrEqualToThreshold"
6+
evaluation_periods = 1
7+
metric_name = "Errors"
8+
namespace = "AWS/Lambda"
9+
period = 60
10+
statistic = "Maximum"
11+
threshold = 1
12+
unit = "Count"
13+
alarm_description = "This metric monitors the number of Lambda errors that have occurred"
14+
alarm_actions = [module.lambda_errors_sns_topic.sns_topic_arn]
15+
}

terraform/infrastructure/modules/sns/outputs.tf

Lines changed: 0 additions & 4 deletions
This file was deleted.

terraform/infrastructure/modules/sns/sns.tf

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)