Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/complete-psql-replica/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 6 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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")
Expand All @@ -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
}
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down