hope this fix your issue I don't think you can inline variables inside the policy like that. Instead you need to create a template_file, and feed the result of the template through to the policy. This will create a policy for each bucket (names taken from the previous question)
With these it helps aws_iam_policy_attachment creates exclusive attachment of IAM Policies and override any existing policy attached to the IAM Role. If you are looking to attach multiple policies to a Single IAM Role, then try using aws_iam_role_policy_attachment (https://www.terraform.io/docs/providers/aws/r/iam_role_policy_attachment.html). This resource should help you to achieve your goal.
How do I create an S3 bucket policy from a template in Terraform 0.12?
like below fixes the issue You can use data resource to create a JSON template for policy by passing the variables based on your environment and use that template_file as policy in aws_s3_bucket resource.