Skip to content

Instantly share code, notes, and snippets.

@viesti
Last active June 24, 2020 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viesti/3920eb470db1a54604fa633be3475c37 to your computer and use it in GitHub Desktop.
Save viesti/3920eb470db1a54604fa633be3475c37 to your computer and use it in GitHub Desktop.
locals {
monitoring_emails = [
"user1@example.com",
"user2@example.com"
]
}
resource "aws_sns_topic" "monitoring" {
name = "monitoring"
}
resource "null_resource" "monitoring-email-subscription" {
count = length(local.monitoring_emails)
triggers = {
email = local.monitoring_emails[count.index]
sns_arn = aws_sns_topic.monitoring.arn
}
provisioner "local-exec" {
command = "aws sns subscribe --topic-arn ${self.triggers.sns_arn} --protocol email --notification-endpoint ${self.triggers.email}"
}
provisioner "local-exec" {
when = destroy
command = "aws sns unsubscribe --subscription-arn $(aws sns list-subscriptions-by-topic --topic-arn ${self.triggers.sns_arn} --query 'Subscriptions[?Endpoint == `${self.triggers.email}`].SubscriptionArn' --out text)"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment