Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add bucket_regional_domain_name to aws_s3_bucket Data Source #7765

Merged
merged 3 commits into from
Mar 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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