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 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
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 _, recordSet := range resp.ResourceRecordSets {
name := cleanRecordName(*recordSet.Name)
if FQDN(strings.ToLower(name)) != FQDN(strings.ToLower(*lopts.StartRecordName)) {
continue
}
if strings.ToUpper(*recordSet.Type) != strings.ToUpper(*lopts.StartRecordType) {
continue
}

if record.SetIdentifier != nil && *record.SetIdentifier != d.Get("set_identifier") {
continue
if recordSet.SetIdentifier != nil && *recordSet.SetIdentifier != d.Get("set_identifier") {
continue
}

record = recordSet
return false
}
// The only safe return where a record is found
return record, nil
return !lastPage
})

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