Provides an S3 bucket CORS configuration resource. For more information about CORS, go to Enabling Cross-Origin Resource Sharing in the Amazon S3 User Guide.
resource "aws_s3_bucket" "example" {
bucket = "mybucket"
}
resource "aws_s3_bucket_cors_configuration" "example" {
bucket = aws_s3_bucket.example.id
cors_rule {
allowed_headers = ["*"]
allowed_methods = ["PUT", "POST"]
allowed_origins = ["https://s3-website-test.hashicorp.com"]
expose_headers = ["ETag"]
max_age_seconds = 3000
}
cors_rule {
allowed_methods = ["GET"]
allowed_origins = ["*"]
}
}
This resource supports the following arguments:
bucket
- (Required, Forces new resource) Name of the bucket.expected_bucket_owner
- (Optional, Forces new resource) Account ID of the expected bucket owner.cors_rule
- (Required) Set of origins and methods (cross-origin access that you want to allow). See below. You can configure up to 100 rules.The cors_rule
configuration block supports the following arguments:
allowed_headers
- (Optional) Set of Headers that are specified in the Access-Control-Request-Headers
header.allowed_methods
- (Required) Set of HTTP methods that you allow the origin to execute. Valid values are GET
, PUT
, HEAD
, POST
, and DELETE
.allowed_origins
- (Required) Set of origins you want customers to be able to access the bucket from.expose_headers
- (Optional) Set of headers in the response that you want customers to be able to access from their applications (for example, from a JavaScript XMLHttpRequest
object).id
- (Optional) Unique identifier for the rule. The value cannot be longer than 255 characters.max_age_seconds
- (Optional) Time in seconds that your browser is to cache the preflight response for the specified resource.This resource exports the following attributes in addition to the arguments above:
id
- The bucket
or bucket
and expected_bucket_owner
separated by a comma (,
) if the latter is provided.In Terraform v1.5.0 and later, use an import
block to import S3 bucket CORS configuration using the bucket
or using the bucket
and expected_bucket_owner
separated by a comma (,
). For example:
If the owner (account ID) of the source bucket is the same account used to configure the Terraform AWS Provider, import using the bucket
:
import {
to = aws_s3_bucket_cors_configuration.example
id = "bucket-name"
}
If the owner (account ID) of the source bucket differs from the account used to configure the Terraform AWS Provider, import using the bucket
and expected_bucket_owner
separated by a comma (,
):
import {
to = aws_s3_bucket_cors_configuration.example
id = "bucket-name,123456789012"
}
Using terraform import
to import S3 bucket CORS configuration using the bucket
or using the bucket
and expected_bucket_owner
separated by a comma (,
). For example:
If the owner (account ID) of the source bucket is the same account used to configure the Terraform AWS Provider, import using the bucket
:
% terraform import aws_s3_bucket_cors_configuration.example bucket-name
If the owner (account ID) of the source bucket differs from the account used to configure the Terraform AWS Provider, import using the bucket
and expected_bucket_owner
separated by a comma (,
):
% terraform import aws_s3_bucket_cors_configuration.example bucket-name,123456789012