|
1 | | -resource "aws_sns_topic_policy" "main" { |
2 | | - arn = aws_sns_topic.main.arn |
| 1 | +resource "aws_sns_topic_policy" "main_orig" { |
| 2 | + arn = aws_sns_topic.main_orig.arn |
| 3 | + |
| 4 | + policy = data.aws_iam_policy_document.sns_topic_policy.json |
| 5 | +} |
| 6 | + |
| 7 | +resource "aws_sns_topic_policy" "main_clone" { |
| 8 | + arn = aws_sns_topic.main_clone.arn |
3 | 9 |
|
4 | 10 | policy = data.aws_iam_policy_document.sns_topic_policy.json |
5 | 11 | } |
@@ -29,7 +35,65 @@ data "aws_iam_policy_document" "sns_topic_policy" { |
29 | 35 | ] |
30 | 36 |
|
31 | 37 | resources = [ |
32 | | - aws_sns_topic.main.arn, |
| 38 | + aws_sns_topic.main_orig.arn, |
| 39 | + ] |
| 40 | + |
| 41 | + condition { |
| 42 | + test = "StringEquals" |
| 43 | + variable = "AWS:SourceOwner" |
| 44 | + |
| 45 | + values = [ |
| 46 | + var.aws_account_id, |
| 47 | + ] |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + statement { |
| 52 | + sid = "AllowAllSNSActionsFromSharedAccount" |
| 53 | + effect = "Allow" |
| 54 | + actions = [ |
| 55 | + "SNS:Publish", |
| 56 | + ] |
| 57 | + |
| 58 | + principals { |
| 59 | + type = "AWS" |
| 60 | + identifiers = [ |
| 61 | + "arn:aws:iam::${var.shared_infra_account_id}:root" |
| 62 | + ] |
| 63 | + } |
| 64 | + |
| 65 | + resources = [ |
| 66 | + aws_sns_topic.main_orig.arn, |
| 67 | + ] |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +data "aws_iam_policy_document" "sns_topic_policy_clone" { |
| 72 | + policy_id = "__default_policy_ID" |
| 73 | + |
| 74 | + statement { |
| 75 | + sid = "AllowAllSNSActionsFromAccount" |
| 76 | + effect = "Allow" |
| 77 | + |
| 78 | + principals { |
| 79 | + type = "AWS" |
| 80 | + identifiers = ["*"] |
| 81 | + } |
| 82 | + |
| 83 | + actions = [ |
| 84 | + "SNS:Subscribe", |
| 85 | + "SNS:SetTopicAttributes", |
| 86 | + "SNS:RemovePermission", |
| 87 | + "SNS:Receive", |
| 88 | + "SNS:Publish", |
| 89 | + "SNS:ListSubscriptionsByTopic", |
| 90 | + "SNS:GetTopicAttributes", |
| 91 | + "SNS:DeleteTopic", |
| 92 | + "SNS:AddPermission", |
| 93 | + ] |
| 94 | + |
| 95 | + resources = [ |
| 96 | + aws_sns_topic.main_clone.arn, |
33 | 97 | ] |
34 | 98 |
|
35 | 99 | condition { |
@@ -57,7 +121,7 @@ data "aws_iam_policy_document" "sns_topic_policy" { |
57 | 121 | } |
58 | 122 |
|
59 | 123 | resources = [ |
60 | | - aws_sns_topic.main.arn, |
| 124 | + aws_sns_topic.main_clone.arn, |
61 | 125 | ] |
62 | 126 | } |
63 | 127 | } |
0 commit comments