cloudposse / cloudposse/terraform-aws-sns-lambda-notify-slack

Ability to create multiple SNS topics, each to a different slack channel

Open
#38 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
HCL
Stars
49
Forks
43
PR merge metrics
No merged PRs in 30d

Description

Have a question? Please checkout our [Slack Community](https://slack.cloudposse.com) or visit our [Slack Archive](https://archive.sweetops.com/).

[![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com)

## Describe the Feature

Ability to define multiple SNS topics, each sending to different slack channels. Problem when I do this with the current implementation on the second pass of the loop we get a log group duplicate error:

│ Error: creating CloudWatch Logs Log Group (/aws/lambda/XXX-YYYYYY-default): ResourceAlreadyExistsException: The specified log group already exists

│ with module.notify_slack["b"].module.notify_slack.aws_cloudwatch_log_group.lambda[0],
│ on .terraform/modules/notify_slack.notify_slack/main.tf line 46, in resource "aws_cloudwatch_log_group" "lambda":
│ 46: resource "aws_cloudwatch_log_group" "lambda" {

## Expected Behavior

List or Map of SNS topic to slack channels in a for_each loop to work properly

## Use Case

SNS Topics:
- "slack-a" sns topic sends to slack channel "#a"
- "slack-b" sns topic sends to slack channel "#b"

## Describe Ideal Solution

A clear and concise description of what you want to happen. If you don't know, that's okay.
`
variable "slack_channel" {
description = "List of slack channels"
type = list
default = ["a", "b"]
}

module "notify_slack" {
for_each = toset(var.slack_channel)
source = "git::https://github.com/cloudposse/terraform-aws-sns-lambda-notify-slack?ref=tags/0.5.9"
namespace = var.account_name
name = "slack-${each.key}"
slack_channel = each.key
slack_webhook_url = var.slack_webhook_url
slack_username = var.slack_username
`

## Alternatives Considered

## Additional Context

This issue looks to be a problem with the underlying terraform-aws-modules/notify-slack/aws module

Contributor guide

Open the contributing guide

Research direction

Start with the module configuration in main.tf, especially the aws_cloudwatch_log_group.lambda resource at line 46, and reproduce the issue using the for_each example with channels "a" and "b". Trace why both instances target the same log group and verify that each SNS topic/channel pair can be applied without a ResourceAlreadyExistsException.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, terraform
Domain
cloud, infrastructure
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.