terraform-aws-notify-slack: When passing in SNS Topic, there's a race condition if it's not already created

If the SNS topic passed in is NOT already created, the notify-slack module will fail. This is due to notify-slack’s data objects being resolved before my resource objects.

resource "aws_sns_topic" "my_sns" {
  name  = "my-sns"
}

module "notify_slack" {
  source  = "terraform-aws-modules/notify-slack/aws"
  version = "2.0.0"
  slack_channel        = "my_channel"
  slack_username       = "My SNS"
  slack_webhook_url    = "https://hooks.slack.com/services/<SNIP>"
  sns_topic_name       = aws_sns_topic.my_sns.name  #<<<<<<<
  create_sns_topic     = false                #<<<<<<<<<
  slack_emoji          = ":yuk:"
  lambda_function_name = "${var.name_prefix}-my-slack-lambda"
}

From what I can tell, the only usage of the data resource is to ensure that SNS exists before running, and then to craft the ARN. I’d suggest hand-crafting the ARN with the Topic Name instead. I can submit a PR if it would be helpful.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 20 (15 by maintainers)

Commits related to this issue

Most upvoted comments

I just ran into this issue as well and have hit it in other modules in the past. I believe this is due to a change of behavior in terraform 0.12. The suggested change is we should no longer be looking up data sources from inside modules, but instead we should be passing in the entire resource objects as variables. See https://github.com/hashicorp/terraform/issues/22730 for details.

Finally! 😃

v4.12.0 has been just released.