provider/aws: Add CloudFront hosted_zone_id attribute (#6530)

Added the hosted_zone_id attribute, which aliases to the Route 53
zone ID that can be used to route Alias Resource Record Sets to.

This fixes hashicorp/terraform#6489.
This commit is contained in:
Chris Marchesi 2016-05-08 16:40:30 -07:00 committed by Paul Stack
parent 92f9fab734
commit 84cd31cece
4 changed files with 19 additions and 0 deletions

View File

@ -21,6 +21,10 @@ import (
"github.com/hashicorp/terraform/helper/schema"
)
// cloudFrontRoute53ZoneID defines the route 53 zone ID for CloudFront. This
// is used to set the zone_id attribute.
const cloudFrontRoute53ZoneID = "Z2FDTNDATAQYW2"
// Assemble the *cloudfront.DistributionConfig variable. Calls out to various
// expander functions to convert attributes and sub-attributes to the various
// complex structures which are necessary to properly build the
@ -87,6 +91,7 @@ func flattenDistributionConfig(d *schema.ResourceData, distributionConfig *cloud
d.Set("enabled", distributionConfig.Enabled)
d.Set("price_class", distributionConfig.PriceClass)
d.Set("hosted_zone_id", cloudFrontRoute53ZoneID)
err = d.Set("default_cache_behavior", flattenDefaultCacheBehavior(distributionConfig.DefaultCacheBehavior))
if err != nil {

View File

@ -454,6 +454,10 @@ func resourceAwsCloudFrontDistribution() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"hosted_zone_id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
// retain_on_delete is a non-API attribute that may help facilitate speedy
// deletion of a resoruce. It's mainly here for testing purposes, so
// enable at your own risk.

View File

@ -30,6 +30,11 @@ func TestAccAWSCloudFrontDistribution_S3Origin(t *testing.T) {
testAccCheckCloudFrontDistributionExistence(
"aws_cloudfront_distribution.s3_distribution",
),
resource.TestCheckResourceAttr(
"aws_cloudfront_distribution.s3_distribution",
"hosted_zone_id",
"Z2FDTNDATAQYW2",
),
),
},
},

View File

@ -347,6 +347,10 @@ The following attributes are exported:
* `etag` - The current version of the distribution's information. For example:
`E2QWRUHAPOMQZL`.
* `hosted_zone_id` - The CloudFront Route 53 zone ID that can be used to
route an [Alias Resource Record Set][7] to. This attribute is simply an
alias for the zone ID `Z2FDTNDATAQYW2`.
[1]: http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Introduction.html
[2]: http://docs.aws.amazon.com/AmazonCloudFront/latest/APIReference/CreateDistribution.html
@ -354,3 +358,4 @@ The following attributes are exported:
[4]: http://www.iso.org/iso/country_codes/iso_3166_code_lists/country_names_and_code_elements.htm
[5]: /docs/providers/aws/r/cloudfront_origin_access_identity.html
[6]: https://aws.amazon.com/certificate-manager/
[7]: http://docs.aws.amazon.com/Route53/latest/APIReference/CreateAliasRRSAPI.html