I wanted to update my sns target policy using terraform, below is my code. But my terraform plan is failing with below error.
Expected the start of an expression, but found an invalid expression token.
Error: Argument or block definition required
and the second query is how i can interpolate arn name inside the heredoc. Learning terraform so unsure what is going wrong.
resource "aws_sns_topic_policy" "default" {
arn = aws_sns_topic.topic_name.arn
policy = <<EOF
{
"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": "aws_sns_topic.topic_name.arn",
"Condition": {
"StringEquals": {
"AWS:SourceOwner": "local.account_id"
}
}
},
{
"Sid": "AWSEvents_Datasync",
"Effect": "Allow",
"Principal": {
"Service": "events.amazonaws.com"
},
"Action": "sns:Publish",
"Resource": "aws_sns_topic.topic_name.arn"
}
]
}
EOF
}