Skip to content

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

Open
laughedelic wants to merge 4 commits into
integrations:mainfrom
laughedelic:feat/team-sync-groups-q
Open

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

Conversation

@laughedelic

@laughedelic laughedelic commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

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" {
  prefix_filter = "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

github-actions Bot commented Mar 2, 2026

Copy link
Copy Markdown

👋 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

@deiga deiga left a comment

Copy link
Copy Markdown
Collaborator

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

Comment thread github/data_source_github_organization_team_sync_groups.go Outdated
Comment thread github/data_source_github_organization_team_sync_groups.go Outdated
Comment thread website/docs/d/organization_team_sync_groups.html.markdown Outdated
Comment thread github/data_source_github_organization_team_sync_groups.go Outdated
@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

@deiga deiga left a comment

Copy link
Copy Markdown
Collaborator

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 thread github/data_source_github_organization_team_sync_groups.go Outdated
Comment thread github/data_source_github_organization_team_sync_groups_test.go Outdated
@laughedelic
laughedelic requested a review from deiga March 5, 2026 01:37
Comment thread github/data_source_github_organization_team_sync_groups.go Outdated
@laughedelic
laughedelic requested a review from deiga May 13, 2026 15:36

@stevehipwell stevehipwell left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@laughadelic please could you rebase this PR, please note that we've changed how the docs work and ideally want to generate the docs for this data source via the automation.

Comment thread github/data_source_github_organization_team_sync_groups.go Outdated
Comment thread github/data_source_github_organization_team_sync_groups.go Outdated
@laughedelic
laughedelic force-pushed the feat/team-sync-groups-q branch from e21fe5d to c2041b9 Compare June 28, 2026 20:31
@laughedelic
laughedelic requested a review from stevehipwell June 28, 2026 20:34

@stevehipwell stevehipwell left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for updating @laughedelic, I've added some review comments.

}

if v, ok := d.GetOk("prefix_filter"); ok {
options.Query = v.(string)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
options.Query = v.(string)
q, _ := v.(string)
options.Query = q

Otherwise you'll get a lint failure.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in de55491

"github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
)

func TestAccGithubOrganizationTeamSyncGroupsDataSource_existing(t *testing.T) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
func TestAccGithubOrganizationTeamSyncGroupsDataSource_existing(t *testing.T) {
func TestAccGithubOrganizationTeamSyncGroupsDataSource(t *testing.T) {

Please nest sub-tests using t.Run instead of using steps for separate tests. I suggest the following sub tests.

  • all
    • Single step
  • filtered
    • Step 1 a filter that matches
    • Step 2 change the filter to match nothing

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in de55491


## Example Usage

Retrieve all IdP groups:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please can you update the docs to use the template pattern of automatically inserting the examples and using the schema for the attribute descriptions, meaning this description should be a comment in the example file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in de55491 and d2915b1

}

d.SetId(fmt.Sprintf("%s/github-org-team-sync-groups", orgName))
id, err := buildID(orgName, options.Query)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This might be clearer if we use a placeholder when query isn't set.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in de55491. The ID is now <org>:* when no filter is set, and <org>:<prefix> otherwise

"prefix_filter": {
Type: schema.TypeString,
Optional: true,
Description: "Filters the results to return only those that begin with the specified value.",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm assuming there are rules on the naming of team sync groups? If so we need to validate here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think there's anything to validate here. These names come from the external identity provider rather than from GitHub, so the permitted characters are whatever the IdP allows. Entra ID group names, Okta group names, etc. From my experience with Okta, there isn't any expected format.

laughedelic and others added 4 commits August 17, 2026 02:00
Adds an optional prefix_filter argument to github_organization_team_sync_groups
that filters returned IdP groups to those whose names begin with the given value.
Uses buildID(orgName, options.Query) for the resource ID.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Avoid a lint failure by using a checked type assertion when reading
  the prefix_filter value.
- Use "*" as an explicit placeholder in the data source ID when no
  prefix filter is set, so the ID always has the same shape.
- Restructure the acceptance test into `all` and `filtered` sub-tests
  using t.Run instead of packing unrelated cases into steps. The
  `filtered` sub-test first applies a matching prefix, then switches to
  a prefix that matches nothing.
- Switch the docs template to the standard tfplugindocs pattern: the
  examples are inserted automatically from the example files and the
  attribute documentation comes from the schema. The prose describing
  each example moved into the example files as comments.
The previous hand-written template was replaced with the standard
tfplugindocs pattern in the previous commit, but the examples were not
picked up because they lived in a directory named after the short data
source name. tfplugindocs discovers them under
examples/data-sources/<full_data_source_name>/data-source*.tf, so the
examples move to examples/data-sources/github_organization_team_sync_groups/
and are renamed accordingly.

With the description moved onto the schema, the per-data-source template
no longer adds anything over templates/data-sources.md.tmpl, so it is
removed and the page is now fully generated.
@laughedelic
laughedelic force-pushed the feat/team-sync-groups-q branch from c2041b9 to d2915b1 Compare August 17, 2026 00:12
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

3 participants