Skip to content

feat: add prefix filter to team sync groups data source#3248

Open
laughedelic wants to merge 10 commits intointegrations:mainfrom
laughedelic:feat/team-sync-groups-q
Open

feat: add prefix filter to team sync groups data source#3248
laughedelic wants to merge 10 commits intointegrations:mainfrom
laughedelic:feat/team-sync-groups-q

Conversation

@laughedelic
Copy link
Contributor

@laughedelic laughedelic commented Mar 2, 2026


Before the change?

Currently, the github_organization_team_sync_groups data source fetches all groups (in fixed page sizes of 100). This causes performance issues if a large number of groups are synced into GitHub (we have about 3000 groups being pushed to GitHub, so the refresh of github_organization_team_sync_groups takes 20+ seconds).

After the change?

Now it's possible to filter groups by prefix:

data "github_organization_team_sync_groups" "filtered" {
  q = "myprefix_"
}

Pull request checklist

  • Schema migrations have been created if needed (example)
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)

Does this introduce a breaking change?

  • No

I followed the API and the SDK in naming it q, but I'm open to something more descriptive, e.g. prefix or prefix_filter

@github-actions
Copy link

github-actions bot commented Mar 2, 2026

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

@github-actions github-actions bot added the Type: Feature New feature or request label Mar 2, 2026
Copy link
Collaborator

@deiga deiga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. I left some comments that need addressing

@laughedelic laughedelic requested a review from deiga March 2, 2026 22:54
@laughedelic laughedelic changed the title feat: add query filter to team sync groups data source feat: add prefix filter to team sync groups data source Mar 4, 2026
Copy link
Collaborator

@deiga deiga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, the ID will need to change and thus we need a schema migration

Comment on lines +77 to +81
if options.Query != "" {
d.SetId(fmt.Sprintf("%s/github-org-team-sync-groups/%s", orgName, options.Query))
} else {
d.SetId(fmt.Sprintf("%s/github-org-team-sync-groups", orgName))
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, looking at this makes my skin crawl a bit 😬

While we're at it, let's change to buildID to conform to our standards :)

Suggested change
if options.Query != "" {
d.SetId(fmt.Sprintf("%s/github-org-team-sync-groups/%s", orgName, options.Query))
} else {
d.SetId(fmt.Sprintf("%s/github-org-team-sync-groups", orgName))
}
id, err := buildID(orgName, "team-sync-groups", options.Query)
if err != nil {
return diag.FromErr(err)
}
d.SetId(id)

With this change we'll need you to make a StateUpgrader to migrate the old IDs to new IDs. Look at any of the existing ones to see how to go about it :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see what you mean 😅 I have to admit, I'm moving in the dark here, trying to make the minimal necessary changes, and I don't have a good overview of the whole codebase (yet). Thanks for the guidance.

I didn't know about buildID. But it uses : as a separator. I wonder why the original ID used / 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the query is empty, the id is going to look like orgname:team-sync-groups: with a trailing :. Isn't this odd? Should it be orgname:team-sync-groups instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So how about

Suggested change
if options.Query != "" {
d.SetId(fmt.Sprintf("%s/github-org-team-sync-groups/%s", orgName, options.Query))
} else {
d.SetId(fmt.Sprintf("%s/github-org-team-sync-groups", orgName))
}
idParts := []string{orgName, "team-sync-groups"}
if options.Query != "" {
idParts = append(idParts, options.Query)
}
id, err := buildID(idParts...)
if err != nil {
return diag.FromErr(err)
}
d.SetId(id)

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ID change is done in 0064745 and the migration added in a6e33d8. I hope I'm getting it right, but let me know if I still misunderstood.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I don't think that conditional IDs are great, since that requires then custom logic when parsing them (if necessary). We already have other examples of IDs where they just end with : if the last part is empty

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Back to 3-part IDs: e21fe5d

},
{
Config: `data "github_organization_team_sync_groups" "test" { prefix_filter = "nonexistent_prefix_" }`,
Check: resource.ComposeTestCheckFunc(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use ConfigStateChecks instead of Check

Copy link
Contributor Author

@laughedelic laughedelic Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in ad18a98 + 49d1e01

@laughedelic laughedelic requested a review from deiga March 5, 2026 01:37
Comment on lines +15 to +22
SchemaVersion: 1,
StateUpgraders: []schema.StateUpgrader{
{
Type: dataSourceGithubOrganizationTeamSyncGroupsV0().CoreConfigSchema().ImpliedType(),
Upgrade: dataSourceGithubOrganizationTeamSyncGroupsStateUpgradeV0,
Version: 0,
},
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦 Silly me. Do data sources even need Schema Migrations? @stevehipwell

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT]: Support filter parameter on github_organization_team_sync_groups data source

2 participants