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

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

@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

@laughedelic
laughedelic requested a review from deiga March 5, 2026 01:37
@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.

@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

@laughedelic
laughedelic force-pushed the feat/team-sync-groups-q branch from c2041b9 to d2915b1 Compare August 17, 2026 00:12
laughedelic and others added 4 commits August 31, 2026 08:10
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 <[email protected]>
- 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 d2915b1 to e0bb856 Compare August 31, 2026 06:10
@deiga
deiga requested a balanced review from Copilot August 31, 2026 18:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The positive acceptance test does not verify that the prefix returns matching groups.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

These provider review instructions are being used. This PR adds server-side prefix filtering to the organization team sync groups data source.

Changes:

  • Adds the optional prefix_filter argument.
  • Adds acceptance coverage for filtered and empty results.
  • Updates generated documentation and examples.
File summaries
File Description
github/data_source_github_organization_team_sync_groups.go Implements prefix filtering and filter-aware IDs.
github/data_source_github_organization_team_sync_groups_test.go Adds filter acceptance tests.
docs/data-sources/organization_team_sync_groups.md Documents the new argument and examples.
templates/data-sources/organization_team_sync_groups.md.tmpl Removes the obsolete custom template.
examples/data-sources/organization_team_sync_groups/example_1.tf Removes the legacy example.
examples/data-sources/github_organization_team_sync_groups/data-source_1.tf Adds the standard unfiltered example.
examples/data-sources/github_organization_team_sync_groups/data-source_2.tf Adds the prefix-filter example.
Review details
  • Files reviewed: 7/7 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@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.

I think in this case it could make sense to have a unit test which mocks the GH API enough to verify that the filter prefix is being sent could make sense here 🤔

@stevehipwell

Copy link
Copy Markdown
Collaborator

I think in this case it could make sense to have a unit test which mocks the GH API enough to verify that the filter prefix is being sent could make sense here 🤔

@deiga the whole unit test problem has repercussions. Technically we should have a large number of unit tests to cover all code paths and then a smaller number of integration tests to validate that the system works as a whole. The problem with this code base and the GitHub API is that there isn't currently a strategy to make this work, meaning that unit tests just increase the overhead (cognitive and test duration) without decreasing the integration test overhead as the unit tests can't be trusted to actually represent the GitHub API.

I think we need a separate issue to define how we could structure the tests and check the API to support this, but in the meantime I'd be very cautious about accepting unit tests that mock the GitHub API surface (or even worse undocumented API behaviour).

@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.

This looks good. Please add a named documentation template for the data source for consistency with all existing resources/data-sources using the auto generated documentation.

func dataSourceGithubOrganizationTeamSyncGroups() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceGithubOrganizationTeamSyncGroupsRead,
Description: "Get the external identity provider (IdP) groups for an organization.",

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
Description: "Get the external identity provider (IdP) groups for an organization.",
Description: "Data source to get the external identity provider (IdP) groups for an organization.",

@deiga

deiga commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

@stevehipwell I agree about the unit testing and mocking problems. That's why I proposed to mock the API to verify that the provider is sending the payload we think it should instead of verifying the API itself

@stevehipwell

Copy link
Copy Markdown
Collaborator

@stevehipwell I agree about the unit testing and mocking problems. That's why I proposed to mock the API to verify that the provider is sending the payload we think it should instead of verifying the API itself

The problem is that this doesn't prove anything other than a unit test was written at the same time as the code so they match. Is there a reason why an acceptance test wouldn't work?

@deiga

deiga commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

@stevehipwell I agree about the unit testing and mocking problems. That's why I proposed to mock the API to verify that the provider is sending the payload we think it should instead of verifying the API itself

The problem is that this doesn't prove anything other than a unit test was written at the same time as the code so they match. Is there a reason why an acceptance test wouldn't work?

AFAIK we can't guarantee that a result will be found with an acceptance test since that would require a external IdP connection?

@stevehipwell

Copy link
Copy Markdown
Collaborator

AFAIK we can't guarantee that a result will be found with an acceptance test since that would require a external IdP connection?

Yeah, the test would need a comment explaining how to configure it to function correctly but it's really the only way to check that it actually works with the real API.

This branch has not been deployed

No deployments
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

4 participants