diff --git a/modules/topic/main.tf b/modules/topic/main.tf index 67e01e9..7b217b4 100644 --- a/modules/topic/main.tf +++ b/modules/topic/main.tf @@ -3,6 +3,7 @@ resource "aws_sns_topic" "this" { name = var.name delivery_policy = jsonencode(var.delivery_policy) + policy = jsonencode(var.policy) } data "aws_sns_topic" "this" { diff --git a/modules/topic/tests/topic-with-no-subscriptions/0-setup.tf b/modules/topic/tests/topic-with-no-subscriptions/0-setup.tf index db10e19..4bd1935 100644 --- a/modules/topic/tests/topic-with-no-subscriptions/0-setup.tf +++ b/modules/topic/tests/topic-with-no-subscriptions/0-setup.tf @@ -1,9 +1,5 @@ terraform { required_providers { - test = { - source = "terraform.io/builtin/test" - } - aws = { source = "hashicorp/aws" version = "~> 4.33" diff --git a/modules/topic/tests/topic-with-no-subscriptions/1-example.tf b/modules/topic/tests/topic-with-no-subscriptions/1-example.tf index ad38997..5c88603 100644 --- a/modules/topic/tests/topic-with-no-subscriptions/1-example.tf +++ b/modules/topic/tests/topic-with-no-subscriptions/1-example.tf @@ -1,4 +1,43 @@ module "this" { source = "../../" name = "test-topic" + + policy = { + "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:xxxxxxx:account-alarms-handling-virginia", + "Condition" : { + "StringEquals" : { + "AWS:SourceOwner" : "xxxxxx" + } + } + }, + { + "Sid" : "AWSBudgets-notification-1", + "Effect" : "Allow", + "Principal" : { + "Service" : "budgets.amazonaws.com" + }, + "Action" : "SNS:Publish", + "Resource" : "*" + } + ] + } } diff --git a/modules/topic/tests/topic-with-no-subscriptions/2-assert.tf b/modules/topic/tests/topic-with-no-subscriptions/2-assert.tf index 9b4b2cd..2580ca1 100644 --- a/modules/topic/tests/topic-with-no-subscriptions/2-assert.tf +++ b/modules/topic/tests/topic-with-no-subscriptions/2-assert.tf @@ -1,9 +1,9 @@ -resource "test_assertions" "dummy" { - component = "sns-modules-topic" +# resource "test_assertions" "dummy" { +# component = "sns-modules-topic" - equal "scheme" { - description = "As module does not have any output and data just make sure the case runs. Probably can be thrown away." - got = "all good" - want = "all good" - } -} +# equal "scheme" { +# description = "As module does not have any output and data just make sure the case runs. Probably can be thrown away." +# got = "all good" +# want = "all good" +# } +# } diff --git a/modules/topic/variables.tf b/modules/topic/variables.tf index 999f629..c90572d 100644 --- a/modules/topic/variables.tf +++ b/modules/topic/variables.tf @@ -41,3 +41,9 @@ variable "delivery_policy" { } } } + +variable "policy" { + type = any + description = "The SNS Access policy" + default = null +}