Skip to content

Terraform module that builds and deploys a lamdbda function for the aws-to-slack package.

License

Notifications You must be signed in to change notification settings

plus3it/terraform-aws-slack-notifier

Repository files navigation

pullreminders

terraform-aws-slack-notifier

Terraform module that builds and deploys a lamdbda function for the aws-to-slack package.

Usage

This module supports a couple use cases:

  • Create the aws-to-slack lambda function
  • Create triggers for the lambda function

Just the aws-to-slack Lambda Function

To create just the lambda function, use only the variable hook_url.

module "aws-to-slack" {
  source = "git::https://github.com/plus3it/terraform-aws-slack-notifier.git"

  hook_url = "https://hooks.slack.com/services/your/hook/id"
}

Trigger Notifications from CloudWatch Event Rules

To trigger notifications from CloudWatch Event Rules, use the variable event_rules. This will create the aws-to-slack lambda function, the specified event rule(s), and the trigger, and it will add the necessary permissions to the lambda function. See the section Details for event_rules.

module "aws-to-slack" {
  source = "git::https://github.com/plus3it/terraform-aws-slack-notifier.git"

  hook_url = "https://hooks.slack.com/services/your/hook/id"

  event_rules = [
    {
      pattern = <<-PATTERN
        {
          "detail-type": ["CodeBuild Build State Change"]
          "source": ["aws.codebuild"]
        }
        PATTERN
    }
  ]
}

Variables

Name Description Type Default
hook_url Slack webhook URL; see https://api.slack.com/incoming-webhooks string -
name (Optional) Name to associate with the lambda function string "aws-to-slack"
event_rules (Optional) List of config maps of CloudWatch Event Rules that will trigger notifications string []
sns_trigger (Optional) Toggle to control whether to create an SNS topic and subscription for the lambda function bool false

Details for event_rules

The event_rules variable is a list of config maps. Each map describes an event rule that will be created. The supported structure is depicted below. Only the pattern key is required. More information on the supported JSON for the pattern is available in the Amazon CloudWatch Events documentation.

  event_rules = [
    {
      name        = ""  // Optional. Name for the CloudWatch Event rule. Defaults to var.name_<index>
      description = ""  // Optional. Description for the CloudWatch Event rule. Defaults to "Managed by Terraform"
      pattern     = ""  // Required. JSON object describing events the rule will match.
    }
  ]

Authors

This module is maintained by Plus3 IT Systems.

License

Apache 2 licensed. See the LICENSE.md file for details.

Requirements

Name Version
terraform >= 0.12

Providers

Name Version
aws n/a

Resources

Name Type

Inputs

Name Description Type Default Required
hook_url Slack webhook URL; see https://api.slack.com/incoming-webhooks string n/a yes
create_sns_topic (Optional) Creates an SNS topic and subscribes the lambda function; conflicts with sns_topics bool false no
event_rules (Optional) List of config maps of CloudWatch Event Rules that will trigger notifications list(map(string)) [] no
lambda Object of optional attributes passed on to the lambda module
object({
artifacts_dir = optional(string, "builds")
build_in_docker = optional(bool, false)
create_package = optional(bool, true)
ephemeral_storage_size = optional(number)
ignore_source_code_hash = optional(bool, true)
local_existing_package = optional(string)
memory_size = optional(number, 128)
recreate_missing_package = optional(bool, false)
runtime = optional(string, "nodejs14.x")
s3_bucket = optional(string)
s3_existing_package = optional(map(string))
s3_prefix = optional(string)
store_on_s3 = optional(bool, false)
timeout = optional(number, 300)
})
{} no
name (Optional) Name to associate with the lambda function string "aws-to-slack" no
sns_topics (Optional) List of SNS ARNs the lambda function will be subscribed to; conflicts with create_sns_topic list(string) [] no

Outputs

Name Description
events_rule_arns ARNs of the CloudWatch Event Rules
function_arn The ARN of the Lambda function
function_name The name of the Lambda function
role_arn The ARN of the IAM role created for the Lambda function
role_name The name of the IAM role created for the Lambda function
sns_topic_arn ARN of the SNS Topic
sns_topic_subscription_arns ARN of the SNS Topic Subscription

About

Terraform module that builds and deploys a lamdbda function for the aws-to-slack package.

Resources

License

Stars

Watchers

Forks

Packages

No packages published