-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
61 lines (50 loc) · 1.3 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
data "aws_caller_identity" "default" {
}
# Make a topic
resource "aws_sns_topic" "default" {
name_prefix = "${local.alert_for}-threshold-alerts"
}
resource "aws_sns_topic_policy" "default" {
count = var.add_sns_policy != "true" && var.sns_topic_arn != "" ? 0 : 1
arn = local.sns_topic_arn
policy = data.aws_iam_policy_document.sns_topic_policy.json
}
data "aws_iam_policy_document" "sns_topic_policy" {
policy_id = "__default_policy_ID"
statement {
sid = "__default_statement_ID"
actions = [
"SNS:Subscribe",
"SNS:SetTopicAttributes",
"SNS:RemovePermission",
"SNS:Receive",
"SNS:Publish",
"SNS:ListSubscriptionsByTopic",
"SNS:GetTopicAttributes",
"SNS:DeleteTopic",
"SNS:AddPermission",
]
effect = "Allow"
resources = [local.sns_topic_arn]
principals {
type = "AWS"
identifiers = ["*"]
}
condition {
test = "StringEquals"
variable = "AWS:SourceOwner"
values = [
data.aws_caller_identity.default.account_id
]
}
}
statement {
sid = "Allow ${local.alert_for} CloudwatchEvents"
actions = ["sns:Publish"]
resources = [local.sns_topic_arn]
principals {
type = "Service"
identifiers = ["events.amazonaws.com"]
}
}
}