Skip to content

Commit

Permalink
Merge pull request #15 from dasmeta/DMVP-5761
Browse files Browse the repository at this point in the history
fix(DMVP-5761): Fix null policy
  • Loading branch information
aghamyan44 authored Nov 13, 2024
2 parents bf1ad06 + 97023b9 commit 7be732c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions modules/topic/data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data "aws_caller_identity" "current" {}
30 changes: 30 additions & 0 deletions modules/topic/locals.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
locals {
subscriptions_map = { for subscription in var.subscriptions : "${subscription.protocol}:${coalesce(subscription.name, sha256(subscription.endpoint))}" => subscription }
subscriptions_keys = nonsensitive(keys(local.subscriptions_map))

sns_policy = var.policy == null ? jsonencode({
"Version" : "2008-10-17",
"Id" : "__default_policy_ID",
"Statement" : [
{
"Sid" : "__default_statement_ID",
"Effect" : "Allow",
"Principal" : {
"AWS" : "*"
},
"Action" : [
"SNS:GetTopicAttributes",
"SNS:SetTopicAttributes",
"SNS:AddPermission",
"SNS:RemovePermission",
"SNS:DeleteTopic",
"SNS:Subscribe",
"SNS:ListSubscriptionsByTopic",
"SNS:Publish"
],
"Resource" : "arn:aws:sns:us-east-1:${data.aws_caller_identity.current.account_id}:${var.name}",
"Condition" : {
"StringEquals" : {
"AWS:SourceOwner" : "${data.aws_caller_identity.current.account_id}"
}
}
}
]
}) : jsonencode(var.policy)
}
2 changes: 1 addition & 1 deletion modules/topic/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resource "aws_sns_topic" "this" {

name = var.name
delivery_policy = jsonencode(var.delivery_policy)
policy = jsonencode(var.policy)
policy = local.sns_policy
}

data "aws_sns_topic" "this" {
Expand Down

0 comments on commit 7be732c

Please sign in to comment.