Created
November 28, 2018 17:20
-
-
Save davidvasandani/20d542c0957c7a7222d806f9f5bea690 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "aws_db_event_subscription" "default" { | |
name = "rds-event-sub-${var.environment}" | |
sns_topic = "${aws_sns_topic.default.arn}" | |
source_type = "db-instance" | |
source_ids = ["${aws_db_instance.main_rds_instance.id}"] | |
event_categories = [ | |
"availability", | |
"deletion", | |
"failover", | |
"failure", | |
"low storage", | |
"maintenance", | |
"notification", | |
"read replica", | |
"recovery", | |
"restoration", | |
] | |
} | |
resource "aws_sns_topic" "default" { | |
name = "${var.environment}-rds-events" | |
} | |
resource "aws_lambda_permission" "allow_lambda_sns_to_slack" { | |
statement_id = "AllowSNSToSlackExecutionFromSNS" | |
action = "lambda:invokeFunction" | |
function_name = "${module.sns_to_slack.lambda_function_arn}" | |
principal = "sns.amazonaws.com" | |
source_arn = "${aws_sns_topic.default.arn}" | |
} | |
resource "aws_sns_topic_subscription" "lambda_sns_to_slack" { | |
topic_arn = "${aws_sns_topic.default.arn}" | |
protocol = "lambda" | |
endpoint = "${module.sns_to_slack.lambda_function_arn}" | |
} | |
module "sns_to_slack" { | |
source = "github.com/builtinnya/aws-sns-slack-terraform/module" | |
slack_webhook_url = "hooks.slack.com/services/123/456/789" | |
slack_channel_map = { | |
"topic-name" = "#slack-channel" | |
} | |
# The following variables are optional. | |
lambda_iam_role_name = "${var.environment}-sns-to-slack" | |
lambda_iam_policy_name = "${var.environment}-sns-to-slack-policy" | |
lambda_function_name = "${var.environment}-sns-to-slack" | |
default_username = "AWS Lambda" | |
default_channel = "#ops-notifications" | |
default_emoji = ":aws:" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment