Skip to content

Commit

Permalink
provider/aws: Add CloudFront hosted_zone_id attribute (hashicorp#6530)
Browse files Browse the repository at this point in the history
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#6489.
  • Loading branch information
vancluever authored and cristicalin committed May 24, 2016
1 parent 1f0ecff commit 6040492
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions builtin/providers/aws/resource_aws_cloudfront_distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
),
),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,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
Expand All @@ -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

0 comments on commit 6040492

Please sign in to comment.