Skip to content

Commit

Permalink
Merge branch 'charlyx-data-s3-regional-domain-name'
Browse files Browse the repository at this point in the history
  • Loading branch information
bflad committed Mar 4, 2019
2 parents 7ff8966 + e67f094 commit ac9bd0a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
16 changes: 15 additions & 1 deletion aws/data_source_aws_s3_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ func dataSourceAwsS3Bucket() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"bucket_regional_domain_name": {
Type: schema.TypeString,
Computed: true,
},
"hosted_zone_id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -73,7 +77,17 @@ func dataSourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error {
d.Set("bucket_domain_name", bucketDomainName(bucket))

err = bucketLocation(d, bucket, conn)
return err
if err != nil {
return fmt.Errorf("error getting S3 Bucket location: %s", err)
}

regionalDomainName, err := BucketRegionalDomainName(bucket, d.Get("region").(string))
if err != nil {
return err
}
d.Set("bucket_regional_domain_name", regionalDomainName)

return nil
}

func bucketLocation(d *schema.ResourceData, bucket string, conn *s3.S3) error {
Expand Down
2 changes: 2 additions & 0 deletions aws/data_source_aws_s3_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ func TestAccDataSourceS3Bucket_basic(t *testing.T) {
resource.TestCheckResourceAttr("data.aws_s3_bucket.bucket", "region", region),
resource.TestCheckResourceAttr(
"data.aws_s3_bucket.bucket", "bucket_domain_name", testAccBucketDomainName(rInt)),
resource.TestCheckResourceAttr(
"data.aws_s3_bucket.bucket", "bucket_regional_domain_name", testAccBucketRegionalDomainName(rInt, region)),
resource.TestCheckResourceAttr(
"data.aws_s3_bucket.bucket", "hosted_zone_id", hostedZoneID),
resource.TestCheckNoResourceAttr("data.aws_s3_bucket.bucket", "website_endpoint"),
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/s3_bucket.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ 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`.
* `bucket_regional_domain_name` - The bucket region-specific domain name. The bucket domain name including the region name, please refer [here](https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region) for format. Note: The AWS CloudFront allows specifying S3 region-specific endpoint when creating S3 origin, it will prevent [redirect issues](https://forums.aws.amazon.com/thread.jspa?threadID=216814) from CloudFront to S3 Origin URL.
* `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.
* `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.
Expand Down

0 comments on commit ac9bd0a

Please sign in to comment.