title: Is there a way to add CORS rule to Terraform aws_s3_bucket data source?
body: <p>I have an existing bucket that was not created via Terraform. I'm currently setting a policy on that bucket for additional access rights. I need to add a <code>cors_rule</code> to the bucket, but everything I'm finding suggests that you need to create the <code>resource</code> in order to add the cors rule. Is there a way to add a <code>cors_rule</code> to an existing bucket data source?</p>
  <ul>
  <li>Adding CORS to a bucket that's being created: <a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket#using-cors" rel="nofollow noreferrer">https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket#using-cors</a></li>
  <li>Documentation on the bucket data source: <a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/s3_bucket" rel="nofollow noreferrer">https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/s3_bucket</a></li>
  </ul>
  <pre><code>data &quot;aws_s3_bucket&quot; &quot;my_bucket&quot; {
    bucket = &quot;my-bucket&quot;
  
    # This produces a failure on plan
    cors_rule {
      allowed_headers = [&quot;*&quot;]
      allowed_methods = [&quot;GET&quot;, &quot;HEAD&quot;]
      allowed_origins = [
        &quot;https://example.my-website.com&quot;
      ]
      expose_headers  = [
        &quot;Access-Control-Allow-Origin&quot;,
        &quot;ETag&quot;
      ]
      max_age_seconds = 3000
    }
  }
  
  resource &quot;aws_s3_bucket_policy&quot; &quot;allow_access&quot; {
    bucket = data.aws_s3_bucket.my_bucket.id
    policy = data.aws_iam_policy_document.allow_access.json
  }
  
  data &quot;aws_iam_policy_document&quot; &quot;allow_access&quot; {
    statement {
      sid = &quot;Access&quot;
  
      principals {
        type = &quot;AWS&quot;
        identifiers = [&quot;arn:aws:iam::123456789012:user/test&quot;]
      }
  
      actions = [
        &quot;s3:GetObject&quot;,
        &quot;s3:GetBucketLocation&quot;,
        &quot;s3:ListBucket&quot;,
      ]
  
      resources = [
        data.aws_s3_bucket.my_bucket.arn,
        &quot;${data.aws_s3_bucket.my_bucket.arn}/*&quot;
      ]
    }
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/xWmtz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xWmtz.png" alt="plan error" /></a></p>