File tree Expand file tree Collapse file tree 5 files changed +51
-19
lines changed
Expand file tree Collapse file tree 5 files changed +51
-19
lines changed Original file line number Diff line number Diff line change 1+ resource "awscc_chatbot_slack_channel_configuration" "batch_processor_errors" {
2+ count = var. batch_error_notifications_enabled ? 1 : 0
3+
4+ configuration_name = " ${ local . resource_scope } -batch-processor-errors-slack-channel-config"
5+ iam_role_arn = awscc_iam_role. batch_processor_errors_chatbot [0 ]. arn
6+ slack_channel_id = var. environment == " prod" ? " TODO - make channel" : " C09E48NDP18"
7+ slack_workspace_id = " TJ00QR03U"
8+ sns_topic_arns = [aws_sns_topic . batch_processor_errors [0 ]. arn ]
9+ }
10+
11+ resource "awscc_iam_role" "batch_processor_errors_chatbot" {
12+ count = var. batch_error_notifications_enabled ? 1 : 0
13+
14+ role_name = " ${ local . resource_scope } -batch-processor-errors-chatbot-channel-role"
15+ assume_role_policy_document = jsonencode ({
16+ Version = " 2012-10-17"
17+ Statement = [
18+ {
19+ Action = " sts:AssumeRole"
20+ Effect = " Allow"
21+ Sid = " "
22+ Principal = {
23+ Service = " chatbot.amazonaws.com"
24+ }
25+ },
26+ ]
27+ })
28+ managed_policy_arns = [" arn:aws:iam::aws:policy/AWSResourceExplorerReadOnlyAccess" ]
29+ }
Original file line number Diff line number Diff line change 11resource "aws_sns_topic" "batch_processor_errors" {
2- name = " ${ local . short_prefix } -batch-processor-errors"
2+ count = var. batch_error_notifications_enabled ? 1 : 0
3+ name = " ${ local . resource_scope } -batch-processor-errors"
34}
45
56resource "aws_sns_topic_policy" "batch_processor_errors_topic_policy" {
6- arn = aws_sns_topic. batch_processor_errors . arn
7+ count = var. batch_error_notifications_enabled ? 1 : 0
8+ arn = aws_sns_topic. batch_processor_errors [0 ]. arn
79 policy = jsonencode ({
810 Version = " 2012-10-17" ,
911 Statement = [
@@ -14,14 +16,8 @@ resource "aws_sns_topic_policy" "batch_processor_errors_topic_policy" {
1416 Service = " cloudwatch.amazonaws.com"
1517 },
1618 Action = " SNS:Publish" ,
17- Resource = aws_sns_topic.batch_processor_errors.arn
19+ Resource = aws_sns_topic.batch_processor_errors[ 0 ] .arn
1820 }
1921 ]
2022 })
2123}
22-
23- resource "aws_sns_topic_subscription" "batch_processor_errors_email_target" {
24- topic_arn = aws_sns_topic. batch_processor_errors . arn
25- protocol = " email"
26- endpoint = var. batch_processor_errors_target_email
27- }
Original file line number Diff line number Diff line change @@ -303,6 +303,8 @@ resource "aws_lambda_event_source_mapping" "batch_file_created_sqs_to_lambda" {
303303}
304304
305305resource "aws_cloudwatch_log_metric_filter" "batch_processor_filter_error_logs" {
306+ count = var. batch_error_notifications_enabled ? 1 : 0
307+
306308 name = " ${ local . short_prefix } -BatchProcessorFilterErrorLogsFilter"
307309 pattern = " %\\ [ERROR\\ ]|\\ [CRITICAL\\ ]%"
308310 log_group_name = aws_cloudwatch_log_group. batch_processor_filter_lambda_log_group . name
@@ -315,6 +317,8 @@ resource "aws_cloudwatch_log_metric_filter" "batch_processor_filter_error_logs"
315317}
316318
317319resource "aws_cloudwatch_metric_alarm" "batch_processor_filter_error_alarm" {
320+ count = var. batch_error_notifications_enabled ? 1 : 0
321+
318322 alarm_name = " ${ local . short_prefix } -batch-processor-filter-lambda-error"
319323 comparison_operator = " GreaterThanOrEqualToThreshold"
320324 evaluation_periods = 1
@@ -324,6 +328,6 @@ resource "aws_cloudwatch_metric_alarm" "batch_processor_filter_error_alarm" {
324328 statistic = " Sum"
325329 threshold = 1
326330 alarm_description = " This sets off an alarm for any error logs found in the batch processor filter Lambda function"
327- alarm_actions = [aws_sns_topic . batch_processor_errors . arn ]
331+ alarm_actions = [aws_sns_topic . batch_processor_errors [ 0 ] . arn ]
328332 treat_missing_data = " notBreaching"
329333}
Original file line number Diff line number Diff line change @@ -320,6 +320,8 @@ resource "aws_cloudwatch_log_group" "file_name_processor_log_group" {
320320}
321321
322322resource "aws_cloudwatch_log_metric_filter" "file_name_processor_error_logs" {
323+ count = var. batch_error_notifications_enabled ? 1 : 0
324+
323325 name = " ${ local . short_prefix } -FilenameProcessorErrorLogsFilter"
324326 pattern = " %\\ [ERROR\\ ]|\\ [CRITICAL\\ ]%"
325327 log_group_name = aws_cloudwatch_log_group. file_name_processor_log_group . name
@@ -332,6 +334,8 @@ resource "aws_cloudwatch_log_metric_filter" "file_name_processor_error_logs" {
332334}
333335
334336resource "aws_cloudwatch_metric_alarm" "file_name_processor_error_alarm" {
337+ count = var. batch_error_notifications_enabled ? 1 : 0
338+
335339 alarm_name = " ${ local . short_prefix } -file-name-processor-lambda-error"
336340 comparison_operator = " GreaterThanOrEqualToThreshold"
337341 evaluation_periods = 1
@@ -341,6 +345,6 @@ resource "aws_cloudwatch_metric_alarm" "file_name_processor_error_alarm" {
341345 statistic = " Sum"
342346 threshold = 1
343347 alarm_description = " This sets off an alarm for any error logs found in the file name processor Lambda function"
344- alarm_actions = [aws_sns_topic . batch_processor_errors . arn ]
348+ alarm_actions = [aws_sns_topic . batch_processor_errors [ 0 ] . arn ]
345349 treat_missing_data = " notBreaching"
346350}
Original file line number Diff line number Diff line change @@ -7,14 +7,6 @@ variable "sub_environment" {
77variable "immunisation_account_id" {}
88variable "dspp_core_account_id" {}
99
10- # TODO - change this. Get a shared mailbox/switch to Lambda -> Slack integration
11- # Also should have different config for Prod vs PTL
12- variable "batch_processor_errors_target_email" {
13- 14- description = " The target email address for the Batch Processor Errors SNS topic"
15- type = string
16- }
17-
1810variable "create_mesh_processor" {
1911 default = false
2012}
@@ -43,6 +35,13 @@ variable "pds_check_enabled" {
4335 default = true
4436}
4537
38+ # Remember to switch off in PR envs after testing
39+ variable "batch_error_notifications_enabled" {
40+ default = true
41+ description = " Switch to enable batch processing error notifications to Slack"
42+ type = bool
43+ }
44+
4645variable "has_sub_environment_scope" {
4746 default = false
4847}
You can’t perform that action at this time.
0 commit comments