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

provider/aws: Add ability to update r53 zone comment #5318

Merged
merged 1 commit into from
Feb 26, 2016
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
22 changes: 22 additions & 0 deletions builtin/providers/aws/resource_aws_route53_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the third condition is necessary since d.Set should be able to handle nils, but it does no harm. 😉

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely familiar with what the underlying API does here but it could actually be important as it means that unsetting a comment in the UI will not be reflected in the state if it becomes nil vs empty string? (Also not sure whether removing a comment is even a thing, not overly familiar with R53)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jen20 there is no real risk here. It can be made an empty string but I just wanted to catch any potential panic points :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM then.

d.Set("comment", zone.HostedZone.Config.Comment)
}

// get tags
req := &route53.ListTagsForResourceInput{
ResourceId: aws.String(d.Id()),
Expand All @@ -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") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't comment be set as partial + d.Partial(true) used? It's one API call (out of two) that can fail, right?
Before it was only 1 call for tags, so I don't think d.SetPartial("tags") was actually necessary before.

btw. I think d.SetPartial("tags") in the place where it is now (else block) is completely useless (putting away the fact that d.Partial(true) isn't called), but maybe I'm just misunderstanding the way this works?

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)
}

Expand Down
45 changes: 45 additions & 0 deletions builtin/providers/aws/resource_aws_route53_zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down