-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.tf
31 lines (25 loc) · 937 Bytes
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Optionally create a sns topic
resource "aws_sns_topic" "this" {
count = var.sns_topic.topic_name != "" ? 1 : 0
name = var.sns_topic.topic_name
display_name = var.sns_topic.display_name
kms_master_key_id = var.sns_topic.kms_key_id
policy = var.sns_topic.policy
tags = var.tags
}
locals {
sns_topic_arn = var.sns_topic.topic_name != "" ? aws_sns_topic.this[0].arn : var.sns_topic_arn
emails = join(",", var.email_addresses_list)
}
# Add the email endpoint
resource "null_resource" "email_subscription" {
depends_on = [local.sns_topic_arn]
count = length(var.email_addresses_list)
provisioner "local-exec" {
command = "aws sns subscribe --topic-arn ${local.sns_topic_arn} --protocol email --notification-endpoint ${var.email_addresses_list[count.index]}"
}
triggers = {
topic_arn = local.sns_topic_arn
emails = local.emails
}
}