Try this, since the bucket is already there with the policy you can run the below command to get the policy inside the tf state
$ terraform import aws_s3_bucket_policy.allow_access_from_another_account my-s3-bucket-name
Once the policy is there in the TF, run the below code in main.tf
So that it will match with the policy in the state and in the plan it will display if it matches with the state or not.
//resource "aws_s3_bucket" "example" {
// bucket = "my-tf-test-bucket"
//}
resource "aws_s3_bucket_policy" "allow_access_from_another_account" {
bucket = "enter the bucket ID from the portal"
policy = data.aws_iam_policy_document.allow_access_from_another_account.json
}
data "aws_iam_policy_document" "allow_access_from_another_account" {
statement {
principals {
type = "AWS"
identifiers = ["123456789012"]
}
actions = [
"s3:GetObject",
"s3:ListBucket",
]
resources = [
"arn for aws bucket",
]
}
}