Skip to content

machadovilaca/terraform-aws-notifications

Repository files navigation

terraform-aws-notifications

Terraform CI Terraform Version Terraform Module Registry License: GPL

Description

This Terraform module allows you to subscribe to notifications from both SNS topics and Cloudwatch log groups. For each of those, you can select where do you want to send the notifications to. You have the option to target Slack and/or and an S3 bucket.

Subscriptions can be made to any AWS service that sends information to any of the previously described sources. In the following example, you can see the subscription for SNS alerts concerning 'Bounce', 'Complaint' and 'Delivery' from an SES instance, and an alert from Cloudwatch for an SNS mobile message sent.

Message Formating

This module supports all messages sent to the subscribed systems. However, as most alerts have a different structure, if one alert message is not currently supported by this module, the notification text will fallback to the alert raw content. The supported alerts will be pretty-printed as described in the formats folder.

Currently being pretty-printed:

Example Usage

module "notifications" {
  source  = "machadovilaca/notifications/aws"
  version = "0.0.1"

  aws_region = var.aws_region

  slack_webhook_url = "https://hooks.slack.com/services/MI8EILOH9/EECHAHQUOONGAHK2FU4LAIC7IEZ6EIBA8"
  slack_channel     = "#sns-notifications"
  slack_username    = "sns-notifcations"

  s3_bucket_name = "notification-logs"
  create_bucket  = true

  sns_subscripted_topics_arns = {
    (aws_sns_topic.tst_notifications["ses_tst_bounces"].arn) = {
      targets = ["SLACK", "S3"]
    },
    (aws_sns_topic.tst_notifications["ses_tst_complaints"].arn) = {
      targets = ["SLACK", "S3"]
    },
    (aws_sns_topic.tst_notifications["ses_tst_deliveries"].arn) = {
      targets = ["S3"]
    }
  }

  cloudwatch_subscripted_log_group_names = {
    "sns/eu-west-1/12345678954328/DirectPublishToPhoneNumber" = {
      targets = ["SLACK"]
    }
  }
}

Requirements

Name Version
terraform >= 0.12.0
aws >= 3.19

Providers

Name Version
archive n/a
aws >= 3.19
random n/a

Modules

No modules.

Resources

Name Type
aws_iam_role.iam_for_lambda resource
aws_lambda_function.notifications_lambda resource
aws_s3_bucket.s3_bucket resource
random_id.generator resource
archive_file.notifications_lambda data source
aws_caller_identity.current data source

Inputs

Name Description Type Default Required
aws_region AWS region string n/a yes
cloudwatch_subscripted_log_group_names Cloudwatch log groups subscribed to lambda map {} no
create_bucket Should create bucket? bool true no
s3_bucket_name S3 bucket name string n/a yes
slack_channel Slack channel to send notifications to string n/a yes
slack_username Slack username that will publish notifications string n/a yes
slack_webhook_url Slack incoming-webhook url string n/a yes
sns_subscripted_topics_arns SNS topic arns subscribed to lambda map {} no

Outputs

Name Description
arn The ARN of the Lambda function
function_name The name of the Lambda function name
role_name The name of the IAM role attached to the Lambda Function