Last active
June 24, 2020 11:32
-
-
Save viesti/3920eb470db1a54604fa633be3475c37 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
locals { | |
monitoring_emails = [ | |
"[email protected]", | |
"[email protected]" | |
] | |
} | |
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