Home > Blockchain >  Terraform SNS Subscription Multiple Emails
Terraform SNS Subscription Multiple Emails

Time:06-02

What does the formatting of multiple email addresses for the aws_sns_topic_subscription Terraform resource look like?

resource "aws_sns_topic_subscription" "target" {
  topic_arn = aws_sns_topic.some_sns_topic.arn
  protocol  = "email"
  endpoint  = "[email protected],[email protected]"
}

I've tried many combinations for the endpoint parameter:

endpoint  = "[email protected],[email protected]"
endpoint  = "[email protected]", "[email protected]"
endpoint  = ["[email protected]", "[email protected]"]

I've found nothing online or in the Terraform docs on how to do this. Thanks in advance.

CodePudding user response:

endpoint accepts only one email address if the protocol is email type.

If you have multiple email addresses, you may want to use for_each to create a subscription for each address.

resource "aws_sns_topic_subscription" "target" {
  for_each  = toset(["[email protected]", "[email protected]"])
  topic_arn = aws_sns_topic.some_sns_topic.arn
  protocol  = "email"
  endpoint  = each.value
}
  • Related