-
Notifications
You must be signed in to change notification settings - Fork 0
/
cross_account_topic_policy.tf
70 lines (56 loc) · 1.45 KB
/
cross_account_topic_policy.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
65
66
67
68
69
70
data "aws_caller_identity" "current" {}
resource "aws_sns_topic_policy" "cross_account_topic_subscription_policy" {
count = length(var.cross_account_subscription_ids) > 0 ? 1 : 0
arn = aws_sns_topic.topic.arn
policy = data.aws_iam_policy_document.cross_account_sns_topic_policy.json
}
data "aws_iam_policy_document" "cross_account_sns_topic_policy" {
policy_id = "__default_policy_ID"
statement {
actions = [
"SNS:Subscribe",
"SNS:SetTopicAttributes",
"SNS:RemovePermission",
"SNS:Receive",
"SNS:Publish",
"SNS:ListSubscriptionsByTopic",
"SNS:GetTopicAttributes",
"SNS:DeleteTopic",
"SNS:AddPermission",
]
condition {
test = "StringEquals"
variable = "AWS:SourceOwner"
values = [
data.aws_caller_identity.current.account_id,
]
}
effect = "Allow"
principals {
type = "AWS"
identifiers = ["*"]
}
resources = [
aws_sns_topic.topic.arn,
]
sid = "__default_statement_ID"
}
statement {
effect = "Allow"
actions = [
"SNS:Subscribe",
"SNS:ListSubscriptionsByTopic",
"SNS:Receive",
"SNS:GetTopicAttributes",
"SNS:SetTopicAttributes",
]
principals {
type = "AWS"
identifiers = formatlist("arn:aws:iam::%s:root", var.cross_account_subscription_ids)
}
resources = [
aws_sns_topic.topic.arn,
]
sid = "ReportingAccess"
}
}