providers/aws: Add hosted_zone_id to S3 attrs

This commit is contained in:
Justin Campbell 2015-05-07 12:00:39 -04:00
parent d7c9d8702c
commit 839688d477
3 changed files with 30 additions and 1 deletions

View File

@ -49,6 +49,12 @@ func resourceAwsS3Bucket() *schema.Resource {
},
},
"hosted_zone_id": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"website_endpoint": &schema.Schema{
Type: schema.TypeString,
Optional: true,
@ -143,7 +149,27 @@ func resourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error {
return err
}
// Add website_endpoint as an output
// Fetch the region
location, err := s3conn.GetBucketLocation(
&s3.GetBucketLocationInput{
Bucket: aws.String(d.Id()),
},
)
if err != nil {
return err
}
var region string
if location.LocationConstraint != nil {
region = *location.LocationConstraint
}
// Add the hosted zone ID for this bucket's region as an attribute
hostedZoneID := s3.HostedZoneIDForRegion(region)
if err := d.Set("hosted_zone_id", hostedZoneID); err != nil {
return err
}
// Add website_endpoint as an attribute
endpoint, err := websiteEndpoint(s3conn, d)
if err != nil {
return err

View File

@ -23,6 +23,8 @@ func TestAccAWSS3Bucket_basic(t *testing.T) {
Config: testAccAWSS3BucketConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
resource.TestCheckResourceAttr(
"aws_s3_bucket.bucket", "hosted_zone_id", s3.HostedZoneIDForRegion("us-west-2")),
resource.TestCheckResourceAttr(
"aws_s3_bucket.bucket", "website_endpoint", ""),
),

View File

@ -59,4 +59,5 @@ The website object supports the following:
The following attributes are exported:
* `id` - The name of the bucket.
* `hosted_zone_id` - The [Route 53 Hosted Zone ID](http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_website_region_endpoints) for this bucket's region.
* `website_endpoint` - The website endpoint, if the bucket is configured with a website. If not, this will be an empty string.