From c1791124afae4f9b24a575348ef5254a6474d0b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charles-Henri=20GU=C3=89RIN?= Date: Thu, 28 Feb 2019 15:05:28 +0100 Subject: [PATCH 1/4] :sparkles: Add bucket_regional_domain_name to aws_s3_bucket DataSource --- aws/data_source_aws_s3_bucket.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/aws/data_source_aws_s3_bucket.go b/aws/data_source_aws_s3_bucket.go index 2e3e25a409a..6303fa0008e 100644 --- a/aws/data_source_aws_s3_bucket.go +++ b/aws/data_source_aws_s3_bucket.go @@ -73,7 +73,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 { From 85f2894c9421f0f0787dce576e072d4f1ebb8861 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charles-Henri=20GU=C3=89RIN?= Date: Thu, 28 Feb 2019 15:22:45 +0100 Subject: [PATCH 2/4] :memo: Add bucket_regional_domain_name to the documentation's attributes --- website/docs/d/s3_bucket.html.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/website/docs/d/s3_bucket.html.markdown b/website/docs/d/s3_bucket.html.markdown index 31f1f8312a2..7866b57eb5d 100644 --- a/website/docs/d/s3_bucket.html.markdown +++ b/website/docs/d/s3_bucket.html.markdown @@ -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. From 5a7fd8e72bff835a5e813f0891d8bcd6b4ac23b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charles-Henri=20GU=C3=89RIN?= Date: Thu, 28 Feb 2019 15:55:29 +0100 Subject: [PATCH 3/4] :bug: Add missing attribute in schema --- aws/data_source_aws_s3_bucket.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/aws/data_source_aws_s3_bucket.go b/aws/data_source_aws_s3_bucket.go index 6303fa0008e..194c38217cd 100644 --- a/aws/data_source_aws_s3_bucket.go +++ b/aws/data_source_aws_s3_bucket.go @@ -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, From e67f0944f9842fbcb829693a5afe66d73f4890f9 Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Mon, 4 Mar 2019 09:13:41 -0500 Subject: [PATCH 4/4] tests/data-source/aws_s3_bucket_test: Ensure bucket_regional_domain_name attribute is tested Output from acceptance testing: ``` --- PASS: TestAccDataSourceS3Bucket_basic (29.54s) --- PASS: TestAccDataSourceS3Bucket_website (33.76s) ``` --- aws/data_source_aws_s3_bucket_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/aws/data_source_aws_s3_bucket_test.go b/aws/data_source_aws_s3_bucket_test.go index 1858affaec6..a16d17f725e 100644 --- a/aws/data_source_aws_s3_bucket_test.go +++ b/aws/data_source_aws_s3_bucket_test.go @@ -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"),