Skip to content

Commit

Permalink
Merge pull request #886 from cjgajard/issue-884
Browse files Browse the repository at this point in the history
Fix datasource pagerduty_service_integration not finding service when they're many
  • Loading branch information
cjgajard authored Jun 19, 2024
2 parents c687ad4 + d1c1eaa commit 39dd5be
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 39dd5be

Please sign in to comment.