Data Source: aws_s3_bucket

Provides details about a specific S3 bucket.

This resource may prove useful when setting up a Route53 record, or an origin for a CloudFront Distribution.

Example Usage

Route53 Record

data "aws_s3_bucket" "selected" {
  bucket = "bucket.test.com"
}

data "aws_route53_zone" "test_zone" {
  name         = "test.com."
}

resource "aws_route53_record" "example" {
  zone_id   = "${data.aws_route53_zone.test_zone.id}"
  name      = "bucket"
  type      = "A"

  alias {
    name    = "${data.aws_s3_bucket.selected.website_domain}"
    zone_id = "${data.aws_s3_bucket.selected.hosted_zone_id}"
  }
}

CloudFront Origin

data "aws_s3_bucket" "selected" {
  bucket = "a-test-bucket"
}

resource "aws_cloudfront_distribution" "test" {
  origin {
    domain_name = "${data.aws_s3_bucket.selected.bucket_domain_name}"
    origin_id   = "s3-selected-bucket"
  }
}

Argument Reference

The following arguments are supported:

  • bucket - (Required) The name of the bucket

Attribute Reference

In addition to all arguments above, the following attributes are exported:

  • id - The name of the bucket.
  • arn - The ARN of the bucket. Will be of format arn:aws:s3:::bucketname.
  • bucket_domain_name - The bucket domain name. Will be of format bucketname.s3.amazonaws.com.
  • 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.
  • 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.

© 2018 HashiCorp
Licensed under the MPL 2.0 License.
https://www.terraform.io/docs/providers/aws/d/s3_bucket.html