Skip to content

Policy Deletes and Recreate on its own #69

@Eliran-b

Description

@Eliran-b

Describe the Bug

When creating a multiple statements policy Terraform deletes or creates the second policy every time.

When running first apply the policy created successfully (as it should be).

when running the second apply command (without any code changes) the result is the second statement will be deleted.

module definition:

module "my-topic" {
source = "cloudposse/sns-topic/aws"
version = "~> 0.21.0"

name = "env-${var.environment}-batch-manager-topic"
allowed_aws_services_for_sns_published = ["s3.amazonaws.com"]
subscribers = {
my_lambda = {
protocol = "lambda"
endpoint = module.my-lambda.lambda_function_arn
endpoint_auto_confirms = false
raw_message_delivery = false
},
}

encryption_enabled = false
sns_topic_policy_json = jsonencode({
"Version" : "2012-10-17",
"Statement" : [
{
"Sid" : "AllowSNSS3BucketNotification",
"Effect" : "Allow",
"Principal" : {
"Service" : "s3.amazonaws.com"
},
"Action" : "sns:Publish",
"Resource" : module.my-topic.sns_topic_arn,
"Condition" : {
"ArnEquals" : {
"aws:SourceArn" : module.my-bucket.s3_bucket_arn
}
}
},
{
"Sid" : "Allow-AccountB-To-Subscribe",
"Effect" : "Allow",
"Principal" : {
"AWS" : "arn:aws:iam::some-iam"
},
"Action" : "sns:Subscribe",
"Resource" : module.batch-manager-topic.sns_topic_arn
},
]
})
}

Expected Behavior

The required outcome should be that the second statement won't deleted in the second apply command and there will be no changes to apply.

Steps to Reproduce

create an sns topic with more than one statement policy

Screenshots

first apply:

image

second apply:

image

Environment

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug🐛 An issue with the system

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions