DNXLabs / terraform-aws-chatbot

Utility Module to create AWS Chatbot and its dependencies.
https://modules.dnx.one/
Apache License 2.0
5 stars 4 forks source link

"slack_ids" is not working in terraform module "chatbot" #11

Open ashishera opened 1 year ago

ashishera commented 1 year ago

Contact Details (optional)

Description. What happened?

I'm trying to create multiple channels to push aws notifications to multiple slack channels via aws chatbot. Below is the terraform module that I'm trying to use.

module "chatbot" { source = "DNXLabs/chatbot/aws" version = "2.0.0" alarm_sns_topic_arns = module.sns_topic.sns_topic_arn org_name = "xxx" workspace_name = "xxx" slack_workspace_id = "123" slack_channel_id = "abc" slack_ids = [{"channel" = "def", "workspace" = "123"}, {"channel" = "ghi", "workspace" = "123"}] enabled = "true" logging_level = "INFO" }

The above code works without "slack_ids" parameter and create 1 channel. However, if I want to create/configure mutiple channels, it fails.

Steps to reproduce

module "chatbot" { source = "DNXLabs/chatbot/aws" version = "2.0.0" alarm_sns_topic_arns = module.sns_topic.sns_topic_arn org_name = "xxx" workspace_name = "xxx" slack_workspace_id = "123" slack_channel_id = "abc" slack_ids = [{"channel" = "def", "workspace" = "123"}, {"channel" = "ghi", "workspace" = "123"}] enabled = "true" logging_level = "INFO" }

Expected behavior

It should enable/configure aws chatbot in 3 different slack channels.

Actual behavior

Throws below error.

module.eventbridge.aws_cloudwatch_event_target.this["SNS topic to push notifications on a Slack's channel"]: Refreshing state... [id=scheduled_events_bus-aws-scheduled-events-notifications-rule-terraform-20221116193921633800000001] ╷ │ Error: Error in function call │ │ on .terraform/modules/chatbot/_locals.tf line 14, in locals: │ 14: slack_targets = merge(var.slack_ids, local.primary_target) │ ├──────────────── │ │ while calling merge(maps...) │ │ local.primary_target is map of object with 1 element │ │ var.slack_ids is tuple with 2 elements │ │ Call to function "merge" failed: arguments must be maps or objects, got "tuple". ╵

Occurrence

Frequently

Relevant log output

No response

Code of Conduct

Akeboshiwind commented 1 year ago

Not sure if this is a bug in the documentation or in the code.

It looks like the actual format for slack_ids should be:

slack_ids = {
    <name> = {
        channel   = xxx,
        workspace = xxx,
    },
 }

You can see this is the case by looking here in _locals.tf.

A local variable primary_name is defined and then and then the configuration for primary_target is created as a mapping from primary_name to the configuration. On line 14 slack_targets is created by merging primary_target on top of slack_ids. This assumes that slack_ids is in the same format as primary_target.