Skip to content

Commit

Permalink
Fix data service integration not finding service when they're many
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgajard committed Jun 19, 2024
1 parent c687ad4 commit d1c1eaa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions pagerdutyplugin/data_source_pagerduty_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/PagerDuty/go-pagerduty"
"github.com/PagerDuty/terraform-provider-pagerduty/util"
"github.com/PagerDuty/terraform-provider-pagerduty/util/apiutil"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/diag"
Expand Down Expand Up @@ -53,22 +54,23 @@ func (d *dataSourceIntegration) Read(ctx context.Context, req datasource.ReadReq
}

var found *pagerduty.Service
err := retry.RetryContext(ctx, 2*time.Minute, func() *retry.RetryError {
list, err := d.client.ListServicesWithContext(ctx, pagerduty.ListServiceOptions{})
err := apiutil.All(ctx, func(offset int) (bool, error) {
list, err := d.client.ListServicesWithContext(ctx, pagerduty.ListServiceOptions{
Query: searchName.ValueString(),
Limit: apiutil.Limit,
Offset: uint(offset),
})
if err != nil {
if util.IsBadRequestError(err) {
return retry.NonRetryableError(err)
}
return retry.RetryableError(err)
return false, err
}

for _, service := range list.Services {
if service.Name == searchName.ValueString() {
found = &service
break
return false, nil
}
}
return nil
return list.More, nil
})
if err != nil {
resp.Diagnostics.AddError(
Expand Down
File renamed without changes.

0 comments on commit d1c1eaa

Please sign in to comment.