From 06068206a19c8a22b45e35086c2f3755ea3fd208 Mon Sep 17 00:00:00 2001 From: Rohit Singh Date: Tue, 31 Oct 2023 17:55:07 +0530 Subject: [PATCH 1/2] Added variable to enable/disable slack noti. --- examples/complete/main.tf | 1 + main.tf | 8 ++++++-- variables.tf | 6 ++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/examples/complete/main.tf b/examples/complete/main.tf index f667383..5b05644 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -121,6 +121,7 @@ module "rds-pg" { cloudwatch_metric_alarms_enabled = true alarm_cpu_threshold_percent = 70 disk_free_storage_space = "10000000" # in bytes + slack_notification_enabled = false slack_username = "Admin" slack_channel = "postgresql-notification" slack_webhook_url = "https://hooks/xxxxxxxx" diff --git a/main.tf b/main.tf index c2907e9..2a9efa1 100644 --- a/main.tf +++ b/main.tf @@ -244,6 +244,7 @@ EOF } data "archive_file" "lambdazip" { + count = var.slack_notification_enabled ? 1 : 0 type = "zip" output_path = "${path.module}/lambda/sns_slack.zip" @@ -252,6 +253,7 @@ data "archive_file" "lambdazip" { module "cw_sns_slack" { + count = var.slack_notification_enabled ? 1 : 0 source = "./lambda" name = format("%s-%s-%s", var.environment, var.name, "sns-slack") @@ -273,16 +275,18 @@ module "cw_sns_slack" { } resource "aws_sns_topic_subscription" "slack-endpoint" { - endpoint = module.cw_sns_slack.arn + count = var.slack_notification_enabled ? 1 : 0 + endpoint = module.cw_sns_slack[0].arn protocol = "lambda" endpoint_auto_confirms = true topic_arn = aws_sns_topic.slack_topic[0].arn } resource "aws_lambda_permission" "sns_lambda_slack_invoke" { + count = var.slack_notification_enabled ? 1 : 0 statement_id = "sns_slackAllowExecutionFromSNS" action = "lambda:InvokeFunction" - function_name = module.cw_sns_slack.arn + function_name = module.cw_sns_slack[0].arn principal = "sns.amazonaws.com" source_arn = aws_sns_topic.slack_topic[0].arn } diff --git a/variables.tf b/variables.tf index 85cbdb7..644bc35 100644 --- a/variables.tf +++ b/variables.tf @@ -234,6 +234,12 @@ variable "ok_actions" { default = [] } +variable "slack_notification_enabled" { + type = bool + description = "Whether to enable/disable slack notification." + default = false +} + variable "slack_webhook_url" { description = "The Slack Webhook URL where notifications will be sent." default = "" From 8638f2d14803b2d0556e8e246e694f2c0c8e2246 Mon Sep 17 00:00:00 2001 From: Rohit Singh Date: Wed, 1 Nov 2023 13:22:35 +0530 Subject: [PATCH 2/2] updated readme and variable for slack --- examples/complete-psql-replica/main.tf | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/complete-psql-replica/main.tf b/examples/complete-psql-replica/main.tf index fabae6c..c1f2fbf 100644 --- a/examples/complete-psql-replica/main.tf +++ b/examples/complete-psql-replica/main.tf @@ -107,6 +107,7 @@ module "rds-pg" { cloudwatch_metric_alarms_enabled = true alarm_cpu_threshold_percent = 70 disk_free_storage_space = "10000000" # in bytes + slack_notification_enabled = false slack_username = "Admin" slack_channel = "postgresql-notification" slack_webhook_url = "https://hooks/xxxxxxxx"