Skip to content

Commit

Permalink
Fix group_connectors limit (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
fivetran-aleksandrboldyrev authored Jan 15, 2025
1 parent b91f2aa commit b11ddd9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
50 changes: 34 additions & 16 deletions fivetran/framework/datasources/group_connectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/fivetran/terraform-provider-fivetran/fivetran/framework/core"
"github.com/fivetran/terraform-provider-fivetran/fivetran/framework/core/model"
"github.com/hashicorp/terraform-plugin-framework/datasource"
sdk "github.com/fivetran/go-fivetran/groups"

fivetranSchema "github.com/fivetran/terraform-provider-fivetran/fivetran/framework/core/schema"
)
Expand Down Expand Up @@ -41,26 +42,43 @@ func (d *groupConnectors) Read(ctx context.Context, req datasource.ReadRequest,
}

var data model.GroupConnectors

resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)

svc := d.GetClient().NewGroupListConnectors().GroupID(data.Id.ValueString())

if !data.Schema.IsNull() {
svc.Schema(data.Schema.ValueString())
}

groupConnectorsResponse, err := svc.Do(ctx)

if err != nil {
resp.Diagnostics.AddError(
"Read error.",
fmt.Sprintf("%v; code: %v; message: %v", err, groupConnectorsResponse.Code, groupConnectorsResponse.Message),
)
return
var respNextCursor string
var listResponse sdk.GroupListConnectorsResponse
limit := 1000

for {
var err error
var tmpResp sdk.GroupListConnectorsResponse
svc := d.GetClient().NewGroupListConnectors()

if respNextCursor == "" {
tmpResp, err = svc.Limit(limit).GroupID(data.Id.ValueString()).Do(ctx)
}

if respNextCursor != "" {
tmpResp, err = svc.Limit(limit).GroupID(data.Id.ValueString()).Cursor(respNextCursor).Do(ctx)
}

if err != nil {
resp.Diagnostics.AddError(
"Read error.",
fmt.Sprintf("%v; code: %v; message: %v", err, tmpResp.Code, tmpResp.Message),
)
listResponse = sdk.GroupListConnectorsResponse{}
}

listResponse.Data.Items = append(listResponse.Data.Items, tmpResp.Data.Items...)

if tmpResp.Data.NextCursor == "" {
break
}

respNextCursor = tmpResp.Data.NextCursor
}

data.ReadFromResponse(ctx, groupConnectorsResponse)
data.ReadFromResponse(ctx, listResponse)

resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}
2 changes: 1 addition & 1 deletion fivetran/tests/e2e/resource_dbt_project_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func TestResourceDbtProjectE2E(t *testing.T) {
//t.Skip("Now for deployment you need to use a third-party provider, which is impossible to do inside the local provider test")
t.Skip("Skip cause deprecated in upstream.")
destinationConfig := `
resource "fivetran_destination" "test_destination" {
provider = fivetran-provider
Expand Down
2 changes: 1 addition & 1 deletion fivetran/tests/e2e/resource_dbt_transformation_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func TestResourceDbtTransformationE2E(t *testing.T) {
t.Skip("Reason: T-705448 (issues with Github auth for project)")
t.Skip("Skip cause deprecated in upstream.")
destinationConfig := `
resource "fivetran_destination" "test_destination" {
provider = fivetran-provider
Expand Down

0 comments on commit b11ddd9

Please sign in to comment.