abhilashshettigar / terraform-aws-cloudwatch-slack

Terraform module for sending CloudWatch Alarm events to Slack

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

terraform-aws-cloudwatch-slack

Terraform module that sends CloudWatch Alarm events to Slack.

Terraform version compatibility

Module version Terraform version
2.x.x 0.12.x
<= 1.x.x 0.11.x

Usage

// Create an SNS topic and send its events to the Luigi Slack channel.

resource "aws_sns_topic" "luigi_slack" {
  name = "luigi-slack-notifications"
}

module "cloudwatch_luigi_slack" {
  source = "github.com/claranet/terraform-aws-cloudwatch-slack?ref=v2.0.0"

  name          = "luigi-slack-notifications"
  sns_topic_arn = aws_sns_topic.luigi_slack.arn
  slack_url     = var.luigi_slack_webhook_url

  tags = {
    Environment = var.envname
  }
}

// Create an SNS topic and send its events to the Customer's Slack channel.

resource "aws_sns_topic" "customer_slack" {
  name = "customer-slack-notifications"
}

module "cloudwatch_customer_slack" {
  source = "github.com/claranet/terraform-aws-cloudwatch-slack?ref=v1.3.3"

  name          = "customer-slack-notifications"
  sns_topic_arn = aws_sns_topic.customer_slack.arn
  slack_url     = var.customer_slack_webhook_url

  tags = {
    Environment = var.envname
  }
}

// Create CloudWatch Alarms and point them to the relevant SNS topics.

resource "aws_cloudwatch_metric_alarm" "database_backup" {
  alarm_name        = "${var.envname}-database-backup"
  alarm_description = "${var.envname} database backup"

  metric_name = "DatabaseBackupSize"
  namespace   = "BashtonBilling"

  dimensions {
    Environment = var.envname
  }

  statistic           = "Average"
  comparison_operator = "LessThanThreshold"
  threshold           = "0"
  period              = "${60 * 60 * 24}"
  evaluation_periods  = "1"
  treat_missing_data  = "missing"

  // Point to the Luigi SNS topic
  insufficient_data_actions = [aws_sns_topic.luigi_slack.arn]
  ok_actions                = [aws_sns_topic.luigi_slack.arn]
}

resource "aws_cloudwatch_metric_alarm" "other_alarm" {
  ...

  // Point to the Customer's SNS topic
  alarm_actions = [aws_sns_topic.customer_slack.arn]
  ok_actions    = [aws_sns_topic.customer_slack.arn]

  ...
}

Inputs

Name Description Type Default Required
alarm_status_emoji string ":x:" no
alarm_user_emoji string "" no
alarm_user_name string "" no
insufficient_data_status_emoji string ":x:" no
insufficient_data_user_emoji string "" no
insufficient_data_user_name string "" no
lambda_layers list <list> no
name The name to use for created resources string n/a yes
ok_status_emoji string ":white_check_mark:" no
ok_user_emoji string "" no
ok_user_name string "" no
slack_url The Slack webhook URL string n/a yes
sns_topic_arn The SNS topic to subscribe to string n/a yes
tags map <map> no
account_append Whether to append the account details to the message bool false no
account_name Optional display name for the account if appending string "" no

About

Terraform module for sending CloudWatch Alarm events to Slack

License:MIT License


Languages

Language:HCL 48.5%Language:Python 43.9%Language:Makefile 7.6%