• Stars
    star
    466
  • Rank 94,105 (Top 2 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created almost 7 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Terraform module to create AWS resources for sending notifications to Slack πŸ‡ΊπŸ‡¦

AWS Notify Slack Terraform module

This module creates an SNS topic (or uses an existing one) and an AWS Lambda function that sends notifications to Slack using the incoming webhooks API.

Start by setting up an incoming webhook integration in your Slack workspace.

Doing serverless with Terraform? Check out serverless.tf framework, which aims to simplify all operations when working with the serverless in Terraform.

Supported Features

  • AWS Lambda runtime Python 3.8
  • Create new SNS topic or use existing one
  • Support plaintext and encrypted version of Slack webhook URL
  • Most of Slack message options are customizable
  • Custom Lambda function
  • Various event types are supported, even generic messages:
    • AWS CloudWatch Alarms
    • AWS CloudWatch LogMetrics Alarms
    • AWS GuardDuty Findings

Usage

module "notify_slack" {
  source  = "terraform-aws-modules/notify-slack/aws"
  version = "~> 5.0"

  sns_topic_name = "slack-topic"

  slack_webhook_url = "https://hooks.slack.com/services/AAA/BBB/CCC"
  slack_channel     = "aws-notification"
  slack_username    = "reporter"
}

Using with Terraform Cloud Agents

Terraform Cloud Agents are a paid feature, available as part of the Terraform Cloud for Business upgrade package.

This module requires Python 3.8. You can customize tfc-agent to include Python using this sample Dockerfile:

FROM hashicorp/tfc-agent:latest
RUN apt-get -y update && apt-get -y install python3.8 python3-pip
ENTRYPOINT ["/bin/tfc-agent"]

Use existing SNS topic or create new

If you want to subscribe the AWS Lambda Function created by this module to an existing SNS topic you should specify create_sns_topic = false as an argument and specify the name of existing SNS topic name in sns_topic_name.

Examples

  • notify-slack-simple - Creates SNS topic which sends messages to Slack channel.
  • cloudwatch-alerts-to-slack - End to end example which shows how to send AWS Cloudwatch alerts to Slack channel and use KMS to encrypt webhook URL.

Local Development and Testing

See the functions for further details.

Requirements

Name Version
terraform >= 1.0
aws >= 4.8

Providers

Name Version
aws >= 4.8

Modules

Name Source Version
lambda terraform-aws-modules/lambda/aws 3.2.0

Resources

Name Type
aws_cloudwatch_log_group.lambda resource
aws_iam_role.sns_feedback_role resource
aws_sns_topic.this resource
aws_sns_topic_subscription.sns_notify_slack resource
aws_caller_identity.current data source
aws_iam_policy_document.lambda data source
aws_iam_policy_document.sns_feedback data source
aws_partition.current data source
aws_region.current data source

Inputs

Name Description Type Default Required
cloudwatch_log_group_kms_key_id The ARN of the KMS Key to use when encrypting log data for Lambda string null no
cloudwatch_log_group_retention_in_days Specifies the number of days you want to retain log events in log group for Lambda. number 0 no
cloudwatch_log_group_tags Additional tags for the Cloudwatch log group map(string) {} no
create Whether to create all resources bool true no
create_sns_topic Whether to create new SNS topic bool true no
enable_sns_topic_delivery_status_logs Whether to enable SNS topic delivery status logs bool false no
iam_policy_path Path of policies to that should be added to IAM role for Lambda Function string null no
iam_role_boundary_policy_arn The ARN of the policy that is used to set the permissions boundary for the role string null no
iam_role_name_prefix A unique role name beginning with the specified prefix string "lambda" no
iam_role_path Path of IAM role to use for Lambda Function string null no
iam_role_tags Additional tags for the IAM role map(string) {} no
kms_key_arn ARN of the KMS key used for decrypting slack webhook url string "" no
lambda_attach_dead_letter_policy Controls whether SNS/SQS dead letter notification policy should be added to IAM role for Lambda Function bool false no
lambda_dead_letter_target_arn The ARN of an SNS topic or SQS queue to notify when an invocation fails. string null no
lambda_description The description of the Lambda function string null no
lambda_function_ephemeral_storage_size Amount of ephemeral storage (/tmp) in MB your Lambda Function can use at runtime. Valid value between 512 MB to 10,240 MB (10 GB). number 512 no
lambda_function_name The name of the Lambda function to create string "notify_slack" no
lambda_function_s3_bucket S3 bucket to store artifacts string null no
lambda_function_store_on_s3 Whether to store produced artifacts on S3 or locally. bool false no
lambda_function_tags Additional tags for the Lambda function map(string) {} no
lambda_function_vpc_security_group_ids List of security group ids when Lambda Function should run in the VPC. list(string) null no
lambda_function_vpc_subnet_ids List of subnet ids when Lambda Function should run in the VPC. Usually private or intra subnets. list(string) null no
lambda_role IAM role attached to the Lambda Function. If this is set then a role will not be created for you. string "" no
lambda_source_path The source path of the custom Lambda function string null no
log_events Boolean flag to enabled/disable logging of incoming events bool false no
putin_khuylo Do you agree that Putin doesn't respect Ukrainian sovereignty and territorial integrity? More info: https://en.wikipedia.org/wiki/Putin_khuylo! bool true no
recreate_missing_package Whether to recreate missing Lambda package if it is missing locally or not bool true no
reserved_concurrent_executions The amount of reserved concurrent executions for this lambda function. A value of 0 disables lambda from being triggered and -1 removes any concurrency limitations number -1 no
slack_channel The name of the channel in Slack for notifications string n/a yes
slack_emoji A custom emoji that will appear on Slack messages string ":aws:" no
slack_username The username that will appear on Slack messages string n/a yes
slack_webhook_url The URL of Slack webhook string n/a yes
sns_topic_feedback_role_description Description of IAM role to use for SNS topic delivery status logging string null no
sns_topic_feedback_role_force_detach_policies Specifies to force detaching any policies the IAM role has before destroying it. bool true no
sns_topic_feedback_role_name Name of the IAM role to use for SNS topic delivery status logging string null no
sns_topic_feedback_role_path Path of IAM role to use for SNS topic delivery status logging string null no
sns_topic_feedback_role_permissions_boundary The ARN of the policy that is used to set the permissions boundary for the IAM role used by SNS topic delivery status logging string null no
sns_topic_feedback_role_tags A map of tags to assign to IAM the SNS topic feedback role map(string) {} no
sns_topic_kms_key_id ARN of the KMS key used for enabling SSE on the topic string "" no
sns_topic_lambda_feedback_role_arn IAM role for SNS topic delivery status logs. If this is set then a role will not be created for you. string "" no
sns_topic_lambda_feedback_sample_rate The percentage of successful deliveries to log number 100 no
sns_topic_name The name of the SNS topic to create string n/a yes
sns_topic_tags Additional tags for the SNS topic map(string) {} no
subscription_filter_policy (Optional) A valid filter policy that will be used in the subscription to filter messages seen by the target resource. string null no
subscription_filter_policy_scope (Optional) A valid filter policy scope MessageAttributes|MessageBody string null no
tags A map of tags to add to all resources map(string) {} no

Outputs

Name Description
lambda_cloudwatch_log_group_arn The Amazon Resource Name (ARN) specifying the log group
lambda_iam_role_arn The ARN of the IAM role used by Lambda function
lambda_iam_role_name The name of the IAM role used by Lambda function
notify_slack_lambda_function_arn The ARN of the Lambda function
notify_slack_lambda_function_invoke_arn The ARN to be used for invoking Lambda function from API Gateway
notify_slack_lambda_function_last_modified The date Lambda function was last modified
notify_slack_lambda_function_name The name of the Lambda function
notify_slack_lambda_function_version Latest published version of your Lambda function
slack_topic_arn The ARN of the SNS topic from which messages will be sent to Slack
sns_topic_feedback_role_arn The Amazon Resource Name (ARN) of the IAM role used for SNS delivery status logging
this_slack_topic_arn The ARN of the SNS topic from which messages will be sent to Slack (backward compatibility for version 4.x)

Authors

Module is maintained by Anton Babenko with help from these awesome contributors.

License

Apache 2 Licensed. See LICENSE for full details.

More Repositories

1

terraform-aws-eks

Terraform module to create Amazon Elastic Kubernetes (EKS) resources πŸ‡ΊπŸ‡¦
HCL
4,372
star
2

terraform-aws-vpc

Terraform module to create AWS VPC resources πŸ‡ΊπŸ‡¦
HCL
2,949
star
3

terraform-aws-lambda

Terraform module, which takes care of a lot of AWS Lambda/serverless tasks (build dependencies, packages, updates, deployments) in countless combinations πŸ‡ΊπŸ‡¦
HCL
899
star
4

terraform-aws-rds

Terraform module to create AWS RDS resources πŸ‡ΊπŸ‡¦
HCL
879
star
5

terraform-aws-iam

Terraform module to create AWS IAM resources πŸ‡ΊπŸ‡¦
HCL
779
star
6

terraform-aws-ec2-instance

Terraform module to create AWS EC2 instance(s) resources πŸ‡ΊπŸ‡¦
HCL
751
star
7

terraform-aws-security-group

Terraform module to create AWS Security Group resources πŸ‡ΊπŸ‡¦
HCL
563
star
8

terraform-aws-ecs

Terraform module to create AWS ECS resources πŸ‡ΊπŸ‡¦
HCL
555
star
9

terraform-aws-atlantis

Terraform module to deploy Atlantis on AWS Fargate πŸ‡ΊπŸ‡¦
HCL
519
star
10

terraform-aws-s3-bucket

Terraform module to create AWS S3 resources πŸ‡ΊπŸ‡¦
HCL
511
star
11

terraform-aws-alb

Terraform module to create AWS Application/Network Load Balancer (ALB/NLB) resources πŸ‡ΊπŸ‡¦
HCL
433
star
12

terraform-aws-rds-aurora

Terraform module to create AWS RDS Aurora resources πŸ‡ΊπŸ‡¦
HCL
384
star
13

terraform-aws-autoscaling

Terraform module to create AWS Auto Scaling resources πŸ‡ΊπŸ‡¦
HCL
292
star
14

terraform-aws-pricing

Terraform module which calculates price of AWS infrastructure (from Terraform state and plan) πŸ‡ΊπŸ‡¦
HCL
183
star
15

terraform-aws-acm

Terraform module to create AWS ACM resources πŸ‡ΊπŸ‡¦
HCL
182
star
16

terraform-aws-cloudwatch

Terraform module to create AWS Cloudwatch resources πŸ‡ΊπŸ‡¦
HCL
163
star
17

terraform-aws-elb

Terraform module to create AWS ELB resources πŸ‡ΊπŸ‡¦
HCL
148
star
18

terraform-aws-apigateway-v2

Terraform module to create AWS API Gateway v2 (HTTP/WebSocket) πŸ‡ΊπŸ‡¦
HCL
146
star
19

terraform-aws-eventbridge

Terraform module to create AWS EventBridge resources πŸ‡ΊπŸ‡¦
HCL
142
star
20

terraform-aws-transit-gateway

Terraform module to create AWS Transit Gateway resources πŸ‡ΊπŸ‡¦
HCL
141
star
21

terraform-aws-route53

Terraform module to create AWS Route53 resources πŸ‡ΊπŸ‡¦
HCL
126
star
22

terraform-aws-cloudfront

Terraform module to create AWS CloudFront resources πŸ‡ΊπŸ‡¦
HCL
119
star
23

terraform-aws-vpn-gateway

Terraform module to create AWS VPN gateway resources πŸ‡ΊπŸ‡¦
HCL
111
star
24

terraform-aws-dynamodb-table

Terraform module to create AWS DynamoDB resources πŸ‡ΊπŸ‡¦
HCL
100
star
25

terraform-aws-sns

Terraform module to create AWS SNS resources πŸ‡ΊπŸ‡¦
HCL
95
star
26

terraform-aws-sqs

Terraform module to create AWS SQS resources πŸ‡ΊπŸ‡¦
HCL
92
star
27

terraform-aws-key-pair

Terraform module to create AWS EC2 key pair resources πŸ‡ΊπŸ‡¦
HCL
83
star
28

terraform-aws-redshift

Terraform module to create AWS Redshift resources πŸ‡ΊπŸ‡¦
HCL
81
star
29

meta

Meta-configurations for repositories, teams, files in terraform-aws-modules organization πŸ‡ΊπŸ‡¦
HCL
76
star
30

terraform-aws-solutions

Set of standalone and reusable AWS/DevOps solutions implemented as Terraform modules πŸ‡ΊπŸ‡¦
HCL
75
star
31

terraform-aws-step-functions

Terraform module to create AWS Step Functions πŸ‡ΊπŸ‡¦
HCL
70
star
32

terraform-aws-dms

Terraform module to create AWS DMS (Database Migration Service) resources πŸ‡ΊπŸ‡¦
HCL
62
star
33

terraform-aws-rds-proxy

Terraform module to create AWS RDS Proxy resources πŸ‡ΊπŸ‡¦
HCL
56
star
34

terraform-aws-msk-kafka-cluster

Terraform module to create AWS MSK (Managed Streaming for Kafka) resources πŸ‡ΊπŸ‡¦
HCL
55
star
35

terraform-aws-datadog-forwarders

Terraform module to create resources on AWS to forward logs/metrics to Datadog πŸ‡ΊπŸ‡¦
HCL
53
star
36

terraform-aws-eks-pod-identity

Terraform module to create AWS EKS Pod Identity resources πŸ‡ΊπŸ‡¦
HCL
52
star
37

terraform-aws-appsync

Terraform module to create AWS AWS AppSync resources πŸ‡ΊπŸ‡¦
HCL
50
star
38

terraform-aws-kms

Terraform module to create AWS KMS resources πŸ‡ΊπŸ‡¦
HCL
49
star
39

terraform-aws-ecr

Terraform module to create AWS ECR resources πŸ‡ΊπŸ‡¦
HCL
49
star
40

terraform-aws-managed-service-grafana

Terraform module to create AWS Managed Service for Grafana (AMG) resources πŸ‡ΊπŸ‡¦
HCL
36
star
41

terraform-aws-batch

Terraform module to create AWS Batch resources πŸ‡ΊπŸ‡¦
HCL
35
star
42

terraform-aws-app-runner

Terraform module to create AWS App Runner resources πŸ‡ΊπŸ‡¦
HCL
32
star
43

terraform-aws-secrets-manager

Terraform module to create AWS Secrets Manager resources πŸ‡ΊπŸ‡¦
HCL
28
star
44

terraform-aws-appconfig

Terraform module to create AWS AppConfig resources πŸ‡ΊπŸ‡¦
HCL
27
star
45

terraform-aws-managed-service-prometheus

Terraform module to create AWS Managed Service for Prometheus (AMP) resources πŸ‡ΊπŸ‡¦
HCL
26
star
46

terraform-aws-efs

Terraform module to create AWS EFS resources πŸ‡ΊπŸ‡¦
HCL
24
star
47

terraform-aws-emr

Terraform module to create AWS EMR resources πŸ‡ΊπŸ‡¦
HCL
23
star
48

.github

Meta-GitHub repository for all terraform-aws-modules repositories πŸ‡ΊπŸ‡¦
22
star
49

terraform-aws-ssm-parameter

Terraform module to create AWS SSM Parameter resources πŸ‡ΊπŸ‡¦
HCL
20
star
50

terraform-aws-s3-object

Terraform module which creates S3 object resources on AWS
HCL
17
star
51

terraform-aws-ebs-optimized

Terraform module to determine if an instance can be flagged for EBS optimization
HCL
17
star
52

terraform-aws-customer-gateway

Terraform module to create AWS Customer Gateway resources πŸ‡ΊπŸ‡¦
HCL
17
star
53

terraform-aws-global-accelerator

Terraform module to create AWS Global Accelerator resources πŸ‡ΊπŸ‡¦
HCL
16
star
54

terraform-aws-memory-db

Terraform module to create AWS MemoryDB resources πŸ‡ΊπŸ‡¦
HCL
16
star
55

terraform-aws-opensearch

Terraform module to create AWS OpenSearch resources πŸ‡ΊπŸ‡¦
HCL
15
star
56

terraform-aws-elasticache

Terraform module to create AWS ElastiCache resources πŸ‡ΊπŸ‡¦
HCL
12
star
57

terraform-aws-network-firewall

Terraform module to create AWS Network Firewall resources πŸ‡ΊπŸ‡¦
HCL
12
star
58

terraform-aws-fsx

Terraform module to create AWS FSx resources πŸ‡ΊπŸ‡¦
HCL
4
star
59

atlantis-demo

Demo repository for Atlantis
3
star