Home > other >  Is there a way to add CORS rule to Terraform aws_s3_bucket data source?
Is there a way to add CORS rule to Terraform aws_s3_bucket data source?

Time:02-09

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 cors_rule to the bucket, but everything I'm finding suggests that you need to create the resource in order to add the cors rule. Is there a way to add a cors_rule to an existing bucket data source?

  • Adding CORS to a bucket that's being created: plan error

    CodePudding user response:

    You can only modify resources that are managed by terraform, not resources brought in as a data source. What you can do is create a resource for your bucket, and then import the existing bucket:

    terraform import aws_s3_bucket.my_bucket my-bucket
    

    The import command will give you a list of all properties set on the bucket. For properties you don't want to manage with terraform, use the ignore argument on the lifecycle block.

  •  Tags:  
  • Related