From d750d4d1cccb08f194cdbc9484825f548be286d2 Mon Sep 17 00:00:00 2001 From: stack72 Date: Thu, 25 Feb 2016 11:51:15 +0000 Subject: [PATCH] provider/aws: Add ability to update r53 zone comment --- .../aws/resource_aws_route53_zone.go | 22 +++++++++ .../aws/resource_aws_route53_zone_test.go | 45 +++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/builtin/providers/aws/resource_aws_route53_zone.go b/builtin/providers/aws/resource_aws_route53_zone.go index d1bf8ddf1..2b2930ac1 100644 --- a/builtin/providers/aws/resource_aws_route53_zone.go +++ b/builtin/providers/aws/resource_aws_route53_zone.go @@ -171,6 +171,10 @@ func resourceAwsRoute53ZoneRead(d *schema.ResourceData, meta interface{}) error d.Set("delegation_set_id", cleanDelegationSetId(*zone.DelegationSet.Id)) } + if zone.HostedZone != nil && zone.HostedZone.Config != nil && zone.HostedZone.Config.Comment != nil { + d.Set("comment", zone.HostedZone.Config.Comment) + } + // get tags req := &route53.ListTagsForResourceInput{ ResourceId: aws.String(d.Id()), @@ -197,12 +201,30 @@ func resourceAwsRoute53ZoneRead(d *schema.ResourceData, meta interface{}) error func resourceAwsRoute53ZoneUpdate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).r53conn + d.Partial(true) + + if d.HasChange("comment") { + zoneInput := route53.UpdateHostedZoneCommentInput{ + Id: aws.String(d.Id()), + Comment: aws.String(d.Get("comment").(string)), + } + + _, err := conn.UpdateHostedZoneComment(&zoneInput) + if err != nil { + return err + } else { + d.SetPartial("comment") + } + } + if err := setTagsR53(conn, d, "hostedzone"); err != nil { return err } else { d.SetPartial("tags") } + d.Partial(false) + return resourceAwsRoute53ZoneRead(d, meta) } diff --git a/builtin/providers/aws/resource_aws_route53_zone_test.go b/builtin/providers/aws/resource_aws_route53_zone_test.go index 7df9c9460..9f9ef0006 100644 --- a/builtin/providers/aws/resource_aws_route53_zone_test.go +++ b/builtin/providers/aws/resource_aws_route53_zone_test.go @@ -85,6 +85,39 @@ func TestAccAWSRoute53Zone_basic(t *testing.T) { }) } +func TestAccAWSRoute53Zone_updateComment(t *testing.T) { + var zone route53.GetHostedZoneOutput + var td route53.ResourceTagSet + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckRoute53ZoneDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccRoute53ZoneConfig, + Check: resource.ComposeTestCheckFunc( + testAccCheckRoute53ZoneExists("aws_route53_zone.main", &zone), + testAccLoadTagsR53(&zone, &td), + testAccCheckTagsR53(&td.Tags, "foo", "bar"), + resource.TestCheckResourceAttr( + "aws_route53_zone.main", "comment", "Custom comment"), + ), + }, + + resource.TestStep{ + Config: testAccRoute53ZoneConfigUpdateComment, + Check: resource.ComposeTestCheckFunc( + testAccCheckRoute53ZoneExists("aws_route53_zone.main", &zone), + testAccLoadTagsR53(&zone, &td), + resource.TestCheckResourceAttr( + "aws_route53_zone.main", "comment", "Change Custom Comment"), + ), + }, + }, + }) +} + func TestAccAWSRoute53Zone_private_basic(t *testing.T) { var zone route53.GetHostedZoneOutput @@ -287,6 +320,18 @@ resource "aws_route53_zone" "main" { } ` +const testAccRoute53ZoneConfigUpdateComment = ` +resource "aws_route53_zone" "main" { + name = "hashicorp.com" + comment = "Change Custom Comment" + + tags { + foo = "bar" + Name = "tf-route53-tag-test" + } +} +` + const testAccRoute53PrivateZoneConfig = ` resource "aws_vpc" "main" { cidr_block = "172.29.0.0/24"