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

aws: add pagination support to the findRecord func for route53 #3900

Merged
merged 3 commits into from
Apr 2, 2018
Merged
Changes from 2 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
42 changes: 25 additions & 17 deletions aws/resource_aws_route53_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,27 +638,35 @@ func findRecord(d *schema.ResourceData, meta interface{}) (*route53.ResourceReco

log.Printf("[DEBUG] List resource records sets for zone: %s, opts: %s",
zone, lopts)
resp, err := conn.ListResourceRecordSets(lopts)
if err != nil {
return nil, err
}

for _, record := range resp.ResourceRecordSets {
name := cleanRecordName(*record.Name)
if FQDN(strings.ToLower(name)) != FQDN(strings.ToLower(*lopts.StartRecordName)) {
continue
}
if strings.ToUpper(*record.Type) != strings.ToUpper(*lopts.StartRecordType) {
continue
}
var record *route53.ResourceRecordSet
err = conn.ListResourceRecordSetsPages(lopts, func(resp *route53.ListResourceRecordSetsOutput, lastPage bool) bool {
for _, record = range resp.ResourceRecordSets {
Copy link
Contributor

Choose a reason for hiding this comment

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

For clarity, we should utilize a separate variable here instead of the record we want to return, e.g.

for _, recordSet := range respResourceRecordSets {

Then we can set record to the correct value when its correctly found and not introduce the awkward record = nil each loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. 👍

name := cleanRecordName(*record.Name)
if FQDN(strings.ToLower(name)) != FQDN(strings.ToLower(*lopts.StartRecordName)) {
continue
}
if strings.ToUpper(*record.Type) != strings.ToUpper(*lopts.StartRecordType) {
continue
}

if record.SetIdentifier != nil && *record.SetIdentifier != d.Get("set_identifier") {
continue
if record.SetIdentifier != nil && *record.SetIdentifier != d.Get("set_identifier") {
continue
}
return false
}
// The only safe return where a record is found
return record, nil

record = nil
return true
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be return !lastPage so we keep looping until the last page?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't seem to make a difference, but I've gone ahead and changed it. 👍

})

if err != nil {
return nil, err
}
if record == nil {
return nil, r53NoRecordsFound
}
return nil, r53NoRecordsFound
return record, nil
}

func resourceAwsRoute53RecordDelete(d *schema.ResourceData, meta interface{}) error {
Expand Down