title: How can I assign 1 bucket policy to multiple S3 buckets using for_each in Terraform?
body: <p>I'm trying to for loop and get get the interpolation correct:</p>
  <pre><code>variable &quot;my_bucket_names&quot; {
    type = list(string)
    default = [
      &quot;b1&quot;,
      &quot;b2&quot;,
    ]
  }
  
  resource &quot;aws_s3_bucket_policy&quot; &quot;tf-thing-audit-policy&quot; {
    for_each           = toset(var.my_bucket_names)
    bucket = ${each.key.id} 
  ...
  </code></pre>
  <p>Is there a way I can interpolate on the <code>bucket</code> value?</p>
  <h2>Error:</h2>
  <pre><code>│ Expected the start of an expression, but found an invalid expression token.
  </code></pre>