Can we add an SNS topic from Terraform with Email subscription

Viewed 8919

Hi I was wondering if we can add an SNS topic from Terraform with Email subscription.

So it will be easy to setup Alarms and create SNS topic to send alert to an email with one “Terraform apply” command.

Thanks

3 Answers
resource "aws_sns_topic" "topic" {
  name = "topic-name"
}

resource "aws_sns_topic_subscription" "email-target" {
  topic_arn = aws_sns_topic.topic.arn
  protocol  = "email"
  endpoint  = "example@gmail.com"
}

Terraform currently has a limitation with the provider using Email protocol.

It is unsupported because the endpoint needs to be authorized and does not generate an ARN until the target email address has been validated. This breaks the Terraform model and as a result are not currently supported.

CloudFormation supports this.

However, as others and the docs are point out, terraform doesn't quite support it.

There's a guide that suggests creating a CloudFormation stack within terraform. This stack creates the SNS topic and could also add the subscription.

http://aws-cloud.guru/terraform-sns-topic-email-list/

It could be a solution if you think the effort is worth it

Related