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" 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 = ""