From 5d0f585103d1a4a6e4cf1bbe7e3105963c40493e Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Sun, 28 Jun 2026 22:30:15 +0200 Subject: [PATCH 1/4] feat: add prefix_filter to team sync groups data source 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 --- ...ce_github_organization_team_sync_groups.go | 16 +++++- ...thub_organization_team_sync_groups_test.go | 49 ++++++++++++++++--- 2 files changed, 56 insertions(+), 9 deletions(-) diff --git a/github/data_source_github_organization_team_sync_groups.go b/github/data_source_github_organization_team_sync_groups.go index 643b73b457..4921eb88a6 100644 --- a/github/data_source_github_organization_team_sync_groups.go +++ b/github/data_source_github_organization_team_sync_groups.go @@ -2,7 +2,6 @@ package github import ( "context" - "fmt" "github.com/google/go-github/v89/github" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -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, @@ -49,6 +53,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) @@ -66,7 +74,11 @@ func dataSourceGithubOrganizationTeamSyncGroupsRead(ctx context.Context, d *sche options.Page = resp.NextPageToken } - d.SetId(fmt.Sprintf("%s/github-org-team-sync-groups", orgName)) + id, err := buildID(orgName, options.Query) + 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) } diff --git a/github/data_source_github_organization_team_sync_groups_test.go b/github/data_source_github_organization_team_sync_groups_test.go index c178503395..8a12492110 100644 --- a/github/data_source_github_organization_team_sync_groups_test.go +++ b/github/data_source_github_organization_team_sync_groups_test.go @@ -4,12 +4,15 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/knownvalue" + "github.com/hashicorp/terraform-plugin-testing/statecheck" + "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" ) -func TestAccGithubOrganizationTeamSyncGroupsDataSource_existing(t *testing.T) { +func TestAccGithubOrganizationTeamSyncGroupsDataSource(t *testing.T) { t.Parallel() - t.Run("success", func(t *testing.T) { + t.Run("all", func(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ @@ -18,11 +21,43 @@ func TestAccGithubOrganizationTeamSyncGroupsDataSource_existing(t *testing.T) { Steps: []resource.TestStep{ { Config: `data "github_organization_team_sync_groups" "test" {}`, - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("data.github_organization_team_sync_groups.test", "groups.#"), - resource.TestCheckResourceAttrSet("data.github_organization_team_sync_groups.test", "groups.0.group_id"), - resource.TestCheckResourceAttrSet("data.github_organization_team_sync_groups.test", "groups.0.group_name"), - ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue("data.github_organization_team_sync_groups.test", + tfjsonpath.New("groups"), knownvalue.NotNull()), + statecheck.ExpectKnownValue("data.github_organization_team_sync_groups.test", + tfjsonpath.New("groups").AtSliceIndex(0).AtMapKey("group_id"), knownvalue.NotNull()), + statecheck.ExpectKnownValue("data.github_organization_team_sync_groups.test", + tfjsonpath.New("groups").AtSliceIndex(0).AtMapKey("group_name"), knownvalue.NotNull()), + }, + }, + }, + }) + }) + + t.Run("filtered", func(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { skipUnlessEnterprise(t) }, + ProviderFactories: providerFactories, + Steps: []resource.TestStep{ + { + Config: `data "github_organization_team_sync_groups" "test" { prefix_filter = "acctest-github-provider" }`, + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue("data.github_organization_team_sync_groups.test", + tfjsonpath.New("prefix_filter"), knownvalue.StringExact("acctest-github-provider")), + statecheck.ExpectKnownValue("data.github_organization_team_sync_groups.test", + tfjsonpath.New("groups"), knownvalue.NotNull()), + }, + }, + { + Config: `data "github_organization_team_sync_groups" "test" { prefix_filter = "nonexistent_prefix_" }`, + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue("data.github_organization_team_sync_groups.test", + tfjsonpath.New("prefix_filter"), knownvalue.StringExact("nonexistent_prefix_")), + statecheck.ExpectKnownValue("data.github_organization_team_sync_groups.test", + tfjsonpath.New("groups"), knownvalue.ListSizeExact(0)), + }, }, }, }) From 4f9be63196cd59ebfb59545c6eda2d134c1ec339 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Sun, 28 Jun 2026 22:31:25 +0200 Subject: [PATCH 2/4] Update docs to include prefix_filter argument and example Co-Authored-By: Claude Sonnet 4.6 --- .../organization_team_sync_groups.md | 16 +++++++++++++++- .../organization_team_sync_groups/example_2.tf | 3 +++ .../organization_team_sync_groups.md.tmpl | 10 ++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 examples/data-sources/organization_team_sync_groups/example_2.tf diff --git a/docs/data-sources/organization_team_sync_groups.md b/docs/data-sources/organization_team_sync_groups.md index c3a23f7aff..6727f6d318 100644 --- a/docs/data-sources/organization_team_sync_groups.md +++ b/docs/data-sources/organization_team_sync_groups.md @@ -10,10 +10,24 @@ Use this data source to retrieve the identity provider (IdP) groups for an organ ## Example Usage +Retrieve all IdP groups: + ```terraform -data "github_organization_team_sync_groups" "test" {} +data "github_organization_team_sync_groups" "all" {} ``` +Retrieve IdP groups filtered by a prefix: + +```terraform +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. diff --git a/examples/data-sources/organization_team_sync_groups/example_2.tf b/examples/data-sources/organization_team_sync_groups/example_2.tf new file mode 100644 index 0000000000..e19bf276de --- /dev/null +++ b/examples/data-sources/organization_team_sync_groups/example_2.tf @@ -0,0 +1,3 @@ +data "github_organization_team_sync_groups" "filtered" { + prefix_filter = "myprefix_" +} diff --git a/templates/data-sources/organization_team_sync_groups.md.tmpl b/templates/data-sources/organization_team_sync_groups.md.tmpl index 119f4639d3..89c098a417 100644 --- a/templates/data-sources/organization_team_sync_groups.md.tmpl +++ b/templates/data-sources/organization_team_sync_groups.md.tmpl @@ -10,8 +10,18 @@ Use this data source to retrieve the identity provider (IdP) groups for an organ ## Example Usage +Retrieve all IdP groups: + {{ tffile "examples/data-sources/organization_team_sync_groups/example_1.tf" }} +Retrieve IdP groups filtered by a prefix: + +{{ tffile "examples/data-sources/organization_team_sync_groups/example_2.tf" }} + +## 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. From de554910dcfc27680e9a662ec50243b9973984a1 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Mon, 17 Aug 2026 01:59:26 +0200 Subject: [PATCH 3/4] fix: address review feedback on prefix_filter - 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. --- .../organization_team_sync_groups.md | 29 +++++++++-------- .../example_1.tf | 3 +- .../example_2.tf | 1 + ...ce_github_organization_team_sync_groups.go | 9 ++++-- .../organization_team_sync_groups.md.tmpl | 32 ++++--------------- 5 files changed, 32 insertions(+), 42 deletions(-) diff --git a/docs/data-sources/organization_team_sync_groups.md b/docs/data-sources/organization_team_sync_groups.md index 6727f6d318..1dc0fded8c 100644 --- a/docs/data-sources/organization_team_sync_groups.md +++ b/docs/data-sources/organization_team_sync_groups.md @@ -10,34 +10,35 @@ Use this data source to retrieve the identity provider (IdP) groups for an organ ## Example Usage -Retrieve all IdP groups: - ```terraform +# Retrieve all IdP groups for the organization. data "github_organization_team_sync_groups" "all" {} ``` -Retrieve IdP groups filtered by a prefix: - ```terraform +# Retrieve IdP groups whose names begin with a given prefix. data "github_organization_team_sync_groups" "filtered" { prefix_filter = "myprefix_" } ``` -## Argument Reference + +## Schema -- `prefix_filter` - (Optional) Filters the results to return only those groups whose names begin with this value. +### Optional -## Attributes Reference +- `prefix_filter` (String) Filters the results to return only those that begin with the specified value. -- `groups` - An Array of GitHub Identity Provider Groups. Each `group` block consists of the fields documented below. - ---- +### Read-Only -The `group` block consists of: +- `groups` (List of Object) (see [below for nested schema](#nestedatt--groups)) +- `id` (String) The ID of this resource. -- `group_id` - The ID of the IdP group. + +### Nested Schema for `groups` -- `group_name` - The name of the IdP group. +Read-Only: -- `group_description` - The description of the IdP group. +- `group_description` (String) +- `group_id` (String) +- `group_name` (String) diff --git a/examples/data-sources/organization_team_sync_groups/example_1.tf b/examples/data-sources/organization_team_sync_groups/example_1.tf index 19c77b153c..654bbeada1 100644 --- a/examples/data-sources/organization_team_sync_groups/example_1.tf +++ b/examples/data-sources/organization_team_sync_groups/example_1.tf @@ -1 +1,2 @@ -data "github_organization_team_sync_groups" "test" {} +# Retrieve all IdP groups for the organization. +data "github_organization_team_sync_groups" "all" {} diff --git a/examples/data-sources/organization_team_sync_groups/example_2.tf b/examples/data-sources/organization_team_sync_groups/example_2.tf index e19bf276de..08763a1f65 100644 --- a/examples/data-sources/organization_team_sync_groups/example_2.tf +++ b/examples/data-sources/organization_team_sync_groups/example_2.tf @@ -1,3 +1,4 @@ +# Retrieve IdP groups whose names begin with a given prefix. data "github_organization_team_sync_groups" "filtered" { prefix_filter = "myprefix_" } diff --git a/github/data_source_github_organization_team_sync_groups.go b/github/data_source_github_organization_team_sync_groups.go index 4921eb88a6..a58d1f10f3 100644 --- a/github/data_source_github_organization_team_sync_groups.go +++ b/github/data_source_github_organization_team_sync_groups.go @@ -54,7 +54,8 @@ func dataSourceGithubOrganizationTeamSyncGroupsRead(ctx context.Context, d *sche } if v, ok := d.GetOk("prefix_filter"); ok { - options.Query = v.(string) + q, _ := v.(string) + options.Query = q } groups := make([]any, 0) @@ -74,7 +75,11 @@ func dataSourceGithubOrganizationTeamSyncGroupsRead(ctx context.Context, d *sche options.Page = resp.NextPageToken } - id, err := buildID(orgName, options.Query) + query := options.Query + if query == "" { + query = "*" + } + id, err := buildID(orgName, query) if err != nil { return diag.FromErr(err) } diff --git a/templates/data-sources/organization_team_sync_groups.md.tmpl b/templates/data-sources/organization_team_sync_groups.md.tmpl index 89c098a417..3f6cd8cb28 100644 --- a/templates/data-sources/organization_team_sync_groups.md.tmpl +++ b/templates/data-sources/organization_team_sync_groups.md.tmpl @@ -8,30 +8,12 @@ description: |- Use this data source to retrieve the identity provider (IdP) groups for an organization. -## Example Usage - -Retrieve all IdP groups: - -{{ tffile "examples/data-sources/organization_team_sync_groups/example_1.tf" }} - -Retrieve IdP groups filtered by a prefix: - -{{ tffile "examples/data-sources/organization_team_sync_groups/example_2.tf" }} - -## Argument Reference - -- `prefix_filter` - (Optional) Filters the results to return only those groups whose names begin with this value. +{{- if .HasExamples }} -## Attributes Reference - -- `groups` - An Array of GitHub Identity Provider Groups. Each `group` block consists of the fields documented below. - ---- - -The `group` block consists of: - -- `group_id` - The ID of the IdP group. - -- `group_name` - The name of the IdP group. +## Example Usage +{{ range .ExampleFiles }} +{{ tffile . }} +{{- end }} +{{- end }} -- `group_description` - The description of the IdP group. +{{ .SchemaMarkdown | trimspace }} From d2915b1576c9bdf3d2ff5bbd7f4bfcad6bfb3a20 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Mon, 17 Aug 2026 02:09:33 +0200 Subject: [PATCH 4/4] docs: generate the data source page from schema and examples 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//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. --- .../organization_team_sync_groups.md | 3 ++- .../data-source_1.tf} | 0 .../data-source_2.tf} | 0 ...ce_github_organization_team_sync_groups.go | 1 + .../organization_team_sync_groups.md.tmpl | 19 ------------------- 5 files changed, 3 insertions(+), 20 deletions(-) rename examples/data-sources/{organization_team_sync_groups/example_1.tf => github_organization_team_sync_groups/data-source_1.tf} (100%) rename examples/data-sources/{organization_team_sync_groups/example_2.tf => github_organization_team_sync_groups/data-source_2.tf} (100%) delete mode 100644 templates/data-sources/organization_team_sync_groups.md.tmpl diff --git a/docs/data-sources/organization_team_sync_groups.md b/docs/data-sources/organization_team_sync_groups.md index 1dc0fded8c..69977a57a4 100644 --- a/docs/data-sources/organization_team_sync_groups.md +++ b/docs/data-sources/organization_team_sync_groups.md @@ -1,12 +1,13 @@ --- page_title: "github_organization_team_sync_groups (Data Source) - GitHub" +subcategory: "" description: |- Get the external identity provider (IdP) groups for an organization. --- # github_organization_team_sync_groups (Data Source) -Use this data source to retrieve the identity provider (IdP) groups for an organization. +Get the external identity provider (IdP) groups for an organization. ## Example Usage diff --git a/examples/data-sources/organization_team_sync_groups/example_1.tf b/examples/data-sources/github_organization_team_sync_groups/data-source_1.tf similarity index 100% rename from examples/data-sources/organization_team_sync_groups/example_1.tf rename to examples/data-sources/github_organization_team_sync_groups/data-source_1.tf diff --git a/examples/data-sources/organization_team_sync_groups/example_2.tf b/examples/data-sources/github_organization_team_sync_groups/data-source_2.tf similarity index 100% rename from examples/data-sources/organization_team_sync_groups/example_2.tf rename to examples/data-sources/github_organization_team_sync_groups/data-source_2.tf diff --git a/github/data_source_github_organization_team_sync_groups.go b/github/data_source_github_organization_team_sync_groups.go index a58d1f10f3..e59aee6b4a 100644 --- a/github/data_source_github_organization_team_sync_groups.go +++ b/github/data_source_github_organization_team_sync_groups.go @@ -11,6 +11,7 @@ import ( func dataSourceGithubOrganizationTeamSyncGroups() *schema.Resource { return &schema.Resource{ ReadContext: dataSourceGithubOrganizationTeamSyncGroupsRead, + Description: "Get the external identity provider (IdP) groups for an organization.", Schema: map[string]*schema.Schema{ "prefix_filter": { diff --git a/templates/data-sources/organization_team_sync_groups.md.tmpl b/templates/data-sources/organization_team_sync_groups.md.tmpl deleted file mode 100644 index 3f6cd8cb28..0000000000 --- a/templates/data-sources/organization_team_sync_groups.md.tmpl +++ /dev/null @@ -1,19 +0,0 @@ ---- -page_title: "{{.Name}} ({{.Type}}) - {{.RenderedProviderName}}" -description: |- - Get the external identity provider (IdP) groups for an organization. ---- - -# {{.Name}} ({{.Type}}) - -Use this data source to retrieve the identity provider (IdP) groups for an organization. - -{{- if .HasExamples }} - -## Example Usage -{{ range .ExampleFiles }} -{{ tffile . }} -{{- end }} -{{- end }} - -{{ .SchemaMarkdown | trimspace }}