github.com/adrian-bl/terraform@v0.7.0-rc2.0.20160705220747-de0a34fc3517/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  ### Using object lifecycle
   101  
   102  ```
   103  resource "aws_s3_bucket" "bucket" {
   104  	bucket = "my-bucket"
   105  	acl = "private"
   106  
   107  	lifecycle_rule {
   108  		id = "log"
   109  		prefix = "log/"
   110  		enabled = true
   111  
   112  		transition {
   113  			days = 30
   114  			storage_class = "STANDARD_IA"
   115  		}
   116  		transition {
   117  			days = 60
   118  			storage_class = "GLACIER"
   119  		}
   120  		expiration {
   121  			days = 90
   122  		}
   123  	}
   124  	lifecycle_rule {
   125  		id = "log"
   126  		prefix = "tmp/"
   127  		enabled = true
   128  
   129  		expiration {
   130  			date = "2016-01-12"
   131  		}
   132  	}
   133  }
   134  
   135  resource "aws_s3_bucket" "versioning_bucket" {
   136  	bucket = "my-versioning-bucket"
   137  	acl = "private"
   138  	versioning {
   139  	  enabled = false
   140  	}
   141  	lifecycle_rule {
   142  		prefix = "config/"
   143  		enabled = true
   144  
   145  		noncurrent_version_transition {
   146  			days = 30
   147  			storage_class = "STANDARD_IA"
   148  		}
   149  		noncurrent_version_transition {
   150  			days = 60
   151  			storage_class = "GLACIER"
   152  		}
   153  		noncurrent_version_expiration {
   154  			days = 90
   155  		}
   156  	}
   157  }
   158  ```
   159  
   160  ## Argument Reference
   161  
   162  The following arguments are supported:
   163  
   164  * `bucket` - (Required) The name of the bucket.
   165  * `acl` - (Optional) The [canned ACL](https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl) to apply. Defaults to "private".
   166  * `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.
   167  
   168  * `tags` - (Optional) A mapping of tags to assign to the bucket.
   169  * `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.
   170  * `website` - (Optional) A website object (documented below).
   171  * `cors_rule` - (Optional) A rule of [Cross-Origin Resource Sharing](https://docs.aws.amazon.com/AmazonS3/latest/dev/cors.html) (documented below).
   172  * `versioning` - (Optional) A state of [versioning](https://docs.aws.amazon.com/AmazonS3/latest/dev/Versioning.html) (documented below)
   173  * `logging` - (Optional) A settings of [bucket logging](https://docs.aws.amazon.com/AmazonS3/latest/UG/ManagingBucketLogging.html) (documented below).
   174  * `lifecycle_rule` - (Optional) A configuration of [object lifecycle management](http://docs.aws.amazon.com/AmazonS3/latest/dev/object-lifecycle-mgmt.html) (documented below).
   175  * `acceleration_status` - (Optional) Sets the accelerate configuration of an existing bucket. Can be `Enabled` or `Suspended`.
   176  
   177  The `website` object supports the following:
   178  
   179  * `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.
   180  * `error_document` - (Optional) An absolute path to the document to return in case of a 4XX error.
   181  * `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.
   182  * `routing_rules` - (Optional) A json array containing [routing rules](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-websiteconfiguration-routingrules.html)
   183  describing redirect behavior and when redirects are applied.
   184  
   185  The `CORS` object supports the following:
   186  
   187  * `allowed_headers` (Optional) Specifies which headers are allowed.
   188  * `allowed_methods` (Required) Specifies which methods are allowed. Can be `GET`, `PUT`, `POST`, `DELETE` or `HEAD`.
   189  * `allowed_origins` (Required) Specifies which origins are allowed.
   190  * `expose_headers` (Optional) Specifies expose header in the response.
   191  * `max_age_seconds` (Optional) Specifies time in seconds that browser can cache the response for a preflight request.
   192  
   193  The `versioning` object supports the following:
   194  
   195  * `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.
   196  
   197  The `logging` object supports the following:
   198  
   199  * `target_bucket` - (Required) The name of the bucket that will receive the log objects.
   200  * `target_prefix` - (Optional) To specify a key prefix for log objects.
   201  
   202  The 'lifecycle_rule' object supports the following:
   203  
   204  * `id` - (Optional) Unique identifier for the rule.
   205  * `prefix` - (Required) Object key prefix identifying one or more objects to which the rule applies.
   206  * `enabled` - (Required) Specifies lifecycle rule status.
   207  * `abort_incomplete_multipart_upload_days` (Optional) Specifies the number of days after initiating a multipart upload when the multipart upload must be completed.
   208  * `expiration` - (Optional) Specifies a period in the object's expire (documented below).
   209  * `transition` - (Optional) Specifies a period in the object's transitions (documented below).
   210  * `noncurrent_version_expiration` - (Optional) Specifies when noncurrent object versions expire (documented below).
   211  * `noncurrent_version_transition` - (Optional) Specifies when noncurrent object versions transitions (documented below).
   212  
   213  At least one of `expiration`, `transition`, `noncurrent_version_expiration`, `noncurrent_version_transition` must be specified.
   214  
   215  The `expiration` object supports the following
   216  
   217  * `date` (Optional) Specifies the date after which you want the corresponding action to take effect.
   218  * `days` (Optional) Specifies the number of days after object creation when the specific rule action takes effect.
   219  * `expired_object_delete_marker` (Optional) On a versioned bucket (versioning-enabled or versioning-suspended bucket), you can add this element in the lifecycle configuration to direct Amazon S3 to delete expired object delete markers. 
   220  
   221  The `transition` object supports the following
   222  
   223  * `date` (Optional) Specifies the date after which you want the corresponding action to take effect.
   224  * `days` (Optional) Specifies the number of days after object creation when the specific rule action takes effect.
   225  * `storage_class` (Required) Specifies the Amazon S3 storage class to which you want the object to transition. Can be `STANDARD_IA` or `GLACIER`.
   226  
   227  The `noncurrent_version_expiration` object supports the following
   228  
   229  * `days` (Required) Specifies the number of days an object is noncurrent object versions expire.
   230  
   231  The `noncurrent_version_transition` object supports the following
   232  
   233  * `days` (Required) Specifies the number of days an object is noncurrent object versions expire.
   234  * `storage_class` (Required) Specifies the Amazon S3 storage class to which you want the noncurrent versions object to transition. Can be `STANDARD_IA` or `GLACIER`.
   235  
   236  ## Attributes Reference
   237  
   238  The following attributes are exported:
   239  
   240  * `id` - The name of the bucket.
   241  * `arn` - The ARN of the bucket. Will be of format `arn:aws:s3:::bucketname`
   242  * `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.
   243  * `region` - The AWS region this bucket resides in.
   244  * `website_endpoint` - The website endpoint, if the bucket is configured with a website. If not, this will be an empty string.
   245  * `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.