terraform/website/source/docs/providers/aws/r/s3_bucket.html.markdown

2.2 KiB

layout page_title sidebar_current description
aws AWS: aws_s3_bucket docs-aws-resource-s3-bucket Provides a S3 bucket resource.

aws_s3_bucket

Provides a S3 bucket resource.

Example Usage

Private Bucket w/ Tags

resource "aws_s3_bucket" "b" {
    bucket = "my_tf_test_bucket"
    acl = "private"

    tags {
        Name = "My bucket"
        Environment = "Dev"
    }
}

Static Website Hosting

resource "aws_s3_bucket" "b" {
    bucket = "s3-website-test.hashicorp.com"
    acl = "public-read"
    policy = "${file("policy.json")}"

    website {
        index_document = "index.html"
        error_document = "error.html"
    }
}

Argument Reference

The following arguments are supported:

  • bucket - (Required) The name of the bucket.
  • acl - (Optional) The canned ACL to apply. Defaults to "private".
  • policy - (Optional) A valid bucket policy JSON document.
  • tags - (Optional) A mapping of tags to assign to the bucket.
  • 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.
  • website - (Optional) A website object (documented below).

The website object supports the following:

  • 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.
  • error_document - (Optional) An absolute path to the document to return in case of a 4XX error.
  • redirect_all_requests_to - (Optional) A hostname to redirect all website requests for this bucket to.

Attributes Reference

The following attributes are exported:

  • id - The name of the bucket.
  • hosted_zone_id - The Route 53 Hosted Zone ID for this bucket's region.
  • region - The AWS region this bucket resides in.
  • website_endpoint - The website endpoint, if the bucket is configured with a website. If not, this will be an empty string.