github.com/andresvia/terraform@v0.6.15-0.20160412045437-d51c75946785/website/source/docs/providers/aws/r/s3_bucket.html.markdown (about) 1 --- 2 layout: "aws" 3 page_title: "AWS: aws_s3_bucket" 4 sidebar_current: "docs-aws-resource-s3-bucket" 5 description: |- 6 Provides a S3 bucket resource. 7 --- 8 9 # aws\_s3\_bucket 10 11 Provides a S3 bucket resource. 12 13 ## Example Usage 14 15 ### Private Bucket w/ Tags 16 17 ``` 18 resource "aws_s3_bucket" "b" { 19 bucket = "my_tf_test_bucket" 20 acl = "private" 21 22 tags { 23 Name = "My bucket" 24 Environment = "Dev" 25 } 26 } 27 ``` 28 29 ### Static Website Hosting 30 31 ``` 32 resource "aws_s3_bucket" "b" { 33 bucket = "s3-website-test.hashicorp.com" 34 acl = "public-read" 35 policy = "${file("policy.json")}" 36 37 website { 38 index_document = "index.html" 39 error_document = "error.html" 40 routing_rules = <<EOF 41 [{ 42 "Condition": { 43 "KeyPrefixEquals": "docs/" 44 }, 45 "Redirect": { 46 "ReplaceKeyPrefixWith": "documents/" 47 } 48 }] 49 EOF 50 } 51 } 52 ``` 53 54 ### Using CORS 55 56 ``` 57 resource "aws_s3_bucket" "b" { 58 bucket = "s3-website-test.hashicorp.com" 59 acl = "public-read" 60 61 cors_rule { 62 allowed_headers = ["*"] 63 allowed_methods = ["PUT","POST"] 64 allowed_origins = ["https://s3-website-test.hashicorp.com"] 65 expose_headers = ["ETag"] 66 max_age_seconds = 3000 67 } 68 } 69 ``` 70 71 ### Using versioning 72 73 ``` 74 resource "aws_s3_bucket" "b" { 75 bucket = "my_tf_test_bucket" 76 acl = "private" 77 versioning { 78 enabled = true 79 } 80 } 81 ``` 82 83 ### Enable Logging 84 85 ``` 86 resource "aws_s3_bucket" "log_bucket" { 87 bucket = "my_tf_log_bucket" 88 acl = "log-delivery-write" 89 } 90 resource "aws_s3_bucket" "b" { 91 bucket = "my_tf_test_bucket" 92 acl = "private" 93 logging { 94 target_bucket = "${aws_s3_bucket.log_bucket.id}" 95 target_prefix = "log/" 96 } 97 } 98 ``` 99 100 ## Argument Reference 101 102 The following arguments are supported: 103 104 * `bucket` - (Required) The name of the bucket. 105 * `acl` - (Optional) The [canned ACL](https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl) to apply. Defaults to "private". 106 * `policy` - (Optional) A valid [bucket policy](https://docs.aws.amazon.com/AmazonS3/latest/dev/example-bucket-policies.html) JSON document. Note that if the policy document is not specific enough (but still valid), Terraform may view the policy as constantly changing in a `terraform plan`. In this case, please make sure you use the verbose/specific version of the policy. 107 108 * `tags` - (Optional) A mapping of tags to assign to the bucket. 109 * `force_destroy` - (Optional, Default:false ) A boolean that indicates all objects should be deleted from the bucket so that the bucket can be destroyed without error. These objects are *not* recoverable. 110 * `website` - (Optional) A website object (documented below). 111 * `cors_rule` - (Optional) A rule of [Cross-Origin Resource Sharing](https://docs.aws.amazon.com/AmazonS3/latest/dev/cors.html) (documented below). 112 * `versioning` - (Optional) A state of [versioning](https://docs.aws.amazon.com/AmazonS3/latest/dev/Versioning.html) (documented below) 113 * `logging` - (Optional) A settings of [bucket logging](https://docs.aws.amazon.com/AmazonS3/latest/UG/ManagingBucketLogging.html) (documented below). 114 115 The `website` object supports the following: 116 117 * `index_document` - (Required, unless using `redirect_all_requests_to`) Amazon S3 returns this index document when requests are made to the root domain or any of the subfolders. 118 * `error_document` - (Optional) An absolute path to the document to return in case of a 4XX error. 119 * `redirect_all_requests_to` - (Optional) A hostname to redirect all website requests for this bucket to. Hostname can optionally be prefixed with a protocol (`http://` or `https://`) to use when redirecting requests. The default is the protocol that is used in the original request. 120 * `routing_rules` - (Optional) A json array containing [routing rules](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-websiteconfiguration-routingrules.html) 121 describing redirect behavior and when redirects are applied. 122 123 The `CORS` object supports the following: 124 125 * `allowed_headers` (Optional) Specifies which headers are allowed. 126 * `allowed_methods` (Required) Specifies which methods are allowed. Can be `GET`, `PUT`, `POST`, `DELETE` or `HEAD`. 127 * `allowed_origins` (Required) Specifies which origins are allowed. 128 * `expose_headers` (Optional) Specifies expose header in the response. 129 * `max_age_seconds` (Optional) Specifies time in seconds that browser can cache the response for a preflight request. 130 131 The `versioning` object supports the following: 132 133 * `enabled` - (Optional) Enable versioning. Once you version-enable a bucket, it can never return to an unversioned state. You can, however, suspend versioning on that bucket. 134 135 The `logging` object supports the following: 136 137 * `target_bucket` - (Required) The name of the bucket that will receive the log objects. 138 * `target_prefix` - (Optional) To specify a key prefix for log objects. 139 140 ## Attributes Reference 141 142 The following attributes are exported: 143 144 * `id` - The name of the bucket. 145 * `arn` - The ARN of the bucket. Will be of format `arn:aws:s3:::bucketname` 146 * `hosted_zone_id` - The [Route 53 Hosted Zone ID](https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_website_region_endpoints) for this bucket's region. 147 * `region` - The AWS region this bucket resides in. 148 * `website_endpoint` - The website endpoint, if the bucket is configured with a website. If not, this will be an empty string. 149 * `website_domain` - The domain of the website endpoint, if the bucket is configured with a website. If not, this will be an empty string. This is used to create Route 53 alias records.