-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
64 lines (48 loc) · 1.55 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
62
63
64
# --------------------------------------------------------------------------------------------------
# Set up AWS SNS Topic for config to publish results and send notifications.
# --------------------------------------------------------------------------------------------------
data "aws_region" "current" {}
data "aws_caller_identity" "current" {}
resource "aws_sns_topic" "config" {
name = var.sns_topic_name
policy = data.aws_iam_policy_document.config_sns_access_policy.json
}
data "aws_iam_policy_document" "config_sns_access_policy" {
statement {
sid = "DefaultAWSSNSPolicy"
effect = "Allow"
principals {
type = "AWS"
identifiers = ["*"]
}
actions = [
"SNS:GetTopicAttributes",
"SNS:SetTopicAttributes",
"SNS:AddPermission",
"SNS:RemovePermission",
"SNS:DeleteTopic",
"SNS:Subscribe",
"SNS:ListSubscriptionsByTopic",
"SNS:Publish",
"SNS:Receive",
]
resources = ["arn:aws:sns:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:${var.sns_topic_name}"]
condition {
test = "StringEquals"
variable = "AWS:SourceOwner"
values = [var.sns_topic_owner]
}
}
statement {
sid = "AWSConfigSNSPolicy"
effect = "Allow"
principals {
type = "Service"
identifiers = [
"config.amazonaws.com",
]
}
actions = ["SNS:Publish"]
resources = ["arn:aws:sns:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:${var.sns_topic_name}"]
}
}