Skip to content

Commit

Permalink
Fix pagination for pagerduty_service data source #523
Browse files Browse the repository at this point in the history
  • Loading branch information
josiahp committed Jun 9, 2022
1 parent 3278181 commit aa36376
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions pagerduty/data_source_pagerduty_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,39 @@ func dataSourcePagerDutyServiceRead(d *schema.ResourceData, meta interface{}) er

o := &pagerduty.ListServicesOptions{
Query: searchName,
Limit: 100,
}

return resource.Retry(5*time.Minute, func() *resource.RetryError {
resp, _, err := client.Services.List(o)
if err != nil {
if isErrCode(err, 429) {
// Delaying retry by 30s as recommended by PagerDuty
// https://developer.pagerduty.com/docs/rest-api-v2/rate-limiting/#what-are-possible-workarounds-to-the-events-api-rate-limit
time.Sleep(30 * time.Second)
return resource.RetryableError(err)
}
var found *pagerduty.Service

return resource.NonRetryableError(err)
}
for {
resp, _, err := client.Services.List(o)
if err != nil {
if isErrCode(err, 429) {
// Delaying retry by 30s as recommended by PagerDuty
// https://developer.pagerduty.com/docs/rest-api-v2/rate-limiting/#what-are-possible-workarounds-to-the-events-api-rate-limit
time.Sleep(30 * time.Second)
return resource.RetryableError(err)
}

var found *pagerduty.Service
return resource.NonRetryableError(err)
}

for _, service := range resp.Services {
if service.Name == searchName {
found = service
for _, service := range resp.Services {
if service.Name == searchName {
found = service
break
}
}

if found != nil {
break
}
if !resp.More {
break
}
o.Offset += 100
}

if found == nil {
Expand Down

0 comments on commit aa36376

Please sign in to comment.