Provides an SNS topic policy resource
resource "aws_sns_topic" "test" {
name = "my-topic-with-policy"
}
resource "aws_sns_topic_policy" "default" {
arn = aws_sns_topic.test.arn
policy = data.aws_iam_policy_document.sns_topic_policy.json
}
data "aws_iam_policy_document" "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 = [
var.account-id,
]
}
effect = "Allow"
principals {
type = "AWS"
identifiers = ["*"]
}
resources = [
aws_sns_topic.test.arn,
]
sid = "__default_statement_ID"
}
}
This resource supports the following arguments:
arn
- (Required) The ARN of the SNS topicpolicy
- (Required) The fully-formed AWS policy as JSON. For more information about building AWS IAM policy documents with Terraform, see the AWS IAM Policy Document Guide.This resource exports the following attributes in addition to the arguments above:
owner
- The AWS Account ID of the SNS topic ownerIn Terraform v1.5.0 and later, use an import
block to import SNS Topic Policy using the topic ARN. For example:
import {
to = aws_sns_topic_policy.user_updates
id = "arn:aws:sns:us-west-2:0123456789012:my-topic"
}
Using terraform import
, import SNS Topic Policy using the topic ARN. For example:
% terraform import aws_sns_topic_policy.user_updates arn:aws:sns:us-west-2:0123456789012:my-topic