Skip to content
20 changes: 18 additions & 2 deletions github/data_source_github_organization_team_sync_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package github

import (
"context"
"fmt"

"github.com/google/go-github/v83/github"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand All @@ -14,6 +13,11 @@ func dataSourceGithubOrganizationTeamSyncGroups() *schema.Resource {
ReadContext: dataSourceGithubOrganizationTeamSyncGroupsRead,

Schema: map[string]*schema.Schema{
"prefix_filter": {
Type: schema.TypeString,
Optional: true,
Description: "Filters the results to return only those that begin with the specified value.",
},
"groups": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -48,6 +52,10 @@ func dataSourceGithubOrganizationTeamSyncGroupsRead(ctx context.Context, d *sche
},
}

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

groups := make([]any, 0)
for {
idpGroupList, resp, err := client.Teams.ListIDPGroupsInOrganization(ctx, orgName, options)
Expand All @@ -65,7 +73,15 @@ func dataSourceGithubOrganizationTeamSyncGroupsRead(ctx context.Context, d *sche
options.Page = resp.NextPageToken
}

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)
if err := d.Set("groups", groups); err != nil {
return diag.Errorf("error setting groups: %v", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ func TestAccGithubOrganizationTeamSyncGroupsDataSource_existing(t *testing.T) {
resource.TestCheckResourceAttrSet("data.github_organization_team_sync_groups.test", "groups.0.group_name"),
),
},
{
Config: `data "github_organization_team_sync_groups" "test" { prefix_filter = "nonexistent_prefix_" }`,
Check: resource.ComposeTestCheckFunc(
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 use ConfigStateChecks instead of Check

Copy link
Copy Markdown
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

resource.TestCheckResourceAttr("data.github_organization_team_sync_groups.test", "prefix_filter", "nonexistent_prefix_"),
resource.TestCheckResourceAttr("data.github_organization_team_sync_groups.test", "groups.#", "0"),
),
},
},
})
}
12 changes: 11 additions & 1 deletion website/docs/d/organization_team_sync_groups.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,19 @@ Use this data source to retrieve the identity provider (IdP) groups for an organ
## Example Usage

```hcl
data "github_organization_team_sync_groups" "test" {}
data "github_organization_team_sync_groups" "all" {}
```

```hcl
data "github_organization_team_sync_groups" "filtered" {
prefix_filter = "myprefix_"
}
```

## Argument Reference

* `prefix_filter` - (Optional) Filters the results to return only those groups whose names begin with this value.

## Attributes Reference

* `groups` - An Array of GitHub Identity Provider Groups. Each `group` block consists of the fields documented below.
Expand Down