From 4a81574c19c1d5ee4e661e89b2b3f64d248d4b51 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Mon, 2 Mar 2026 04:21:38 +0100 Subject: [PATCH 01/10] feat: add query filter to team sync groups data source --- ...data_source_github_organization_team_sync_groups.go | 10 +++++++++- ...source_github_organization_team_sync_groups_test.go | 7 +++++++ .../docs/d/organization_team_sync_groups.html.markdown | 8 +++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/github/data_source_github_organization_team_sync_groups.go b/github/data_source_github_organization_team_sync_groups.go index 5ffc3d1f2b..a0b7de5f35 100644 --- a/github/data_source_github_organization_team_sync_groups.go +++ b/github/data_source_github_organization_team_sync_groups.go @@ -14,6 +14,12 @@ func dataSourceGithubOrganizationTeamSyncGroups() *schema.Resource { ReadContext: dataSourceGithubOrganizationTeamSyncGroupsRead, Schema: map[string]*schema.Schema{ + "q": { + Type: schema.TypeString, + Optional: true, + Default: "", + Description: "Filters the results to return only those that begin with the specified value.", + }, "groups": { Type: schema.TypeList, Computed: true, @@ -42,7 +48,9 @@ func dataSourceGithubOrganizationTeamSyncGroupsRead(ctx context.Context, d *sche client := meta.(*Owner).v3client orgName := meta.(*Owner).name + query := d.Get("q").(string) options := &github.ListIDPGroupsOptions{ + Query: query, ListCursorOptions: github.ListCursorOptions{ PerPage: maxPerPage, }, @@ -65,7 +73,7 @@ func dataSourceGithubOrganizationTeamSyncGroupsRead(ctx context.Context, d *sche options.Page = resp.NextPageToken } - d.SetId(fmt.Sprintf("%s/github-org-team-sync-groups", orgName)) + d.SetId(fmt.Sprintf("%s/github-org-team-sync-groups/%s", orgName, query)) 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 a0779c84fb..3efb6c959d 100644 --- a/github/data_source_github_organization_team_sync_groups_test.go +++ b/github/data_source_github_organization_team_sync_groups_test.go @@ -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" { q = "nonexistent_prefix_" }`, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("data.github_organization_team_sync_groups.test", "q", "nonexistent_prefix_"), + resource.TestCheckResourceAttr("data.github_organization_team_sync_groups.test", "groups.#", "0"), + ), + }, }, }) } diff --git a/website/docs/d/organization_team_sync_groups.html.markdown b/website/docs/d/organization_team_sync_groups.html.markdown index 85b36fb436..d8653cde51 100644 --- a/website/docs/d/organization_team_sync_groups.html.markdown +++ b/website/docs/d/organization_team_sync_groups.html.markdown @@ -12,9 +12,15 @@ 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" "test" { + q = "myprefix_" +} ``` +## Argument Reference + +* `q` - (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 b4770696c7d3ef334e6e9b46004a402e88c8a0eb Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Mon, 2 Mar 2026 23:50:20 +0100 Subject: [PATCH 02/10] Rename q to prefix_filter --- github/data_source_github_organization_team_sync_groups.go | 2 +- .../data_source_github_organization_team_sync_groups_test.go | 4 ++-- website/docs/d/organization_team_sync_groups.html.markdown | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/github/data_source_github_organization_team_sync_groups.go b/github/data_source_github_organization_team_sync_groups.go index a0b7de5f35..1bb75556ed 100644 --- a/github/data_source_github_organization_team_sync_groups.go +++ b/github/data_source_github_organization_team_sync_groups.go @@ -14,7 +14,7 @@ func dataSourceGithubOrganizationTeamSyncGroups() *schema.Resource { ReadContext: dataSourceGithubOrganizationTeamSyncGroupsRead, Schema: map[string]*schema.Schema{ - "q": { + "prefix_filter": { Type: schema.TypeString, Optional: true, Default: "", 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 3efb6c959d..614062ea7b 100644 --- a/github/data_source_github_organization_team_sync_groups_test.go +++ b/github/data_source_github_organization_team_sync_groups_test.go @@ -20,9 +20,9 @@ func TestAccGithubOrganizationTeamSyncGroupsDataSource_existing(t *testing.T) { ), }, { - Config: `data "github_organization_team_sync_groups" "test" { q = "nonexistent_prefix_" }`, + Config: `data "github_organization_team_sync_groups" "test" { prefix_filter = "nonexistent_prefix_" }`, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("data.github_organization_team_sync_groups.test", "q", "nonexistent_prefix_"), + resource.TestCheckResourceAttr("data.github_organization_team_sync_groups.test", "prefix_filter", "nonexistent_prefix_"), resource.TestCheckResourceAttr("data.github_organization_team_sync_groups.test", "groups.#", "0"), ), }, diff --git a/website/docs/d/organization_team_sync_groups.html.markdown b/website/docs/d/organization_team_sync_groups.html.markdown index d8653cde51..b32578769e 100644 --- a/website/docs/d/organization_team_sync_groups.html.markdown +++ b/website/docs/d/organization_team_sync_groups.html.markdown @@ -19,7 +19,7 @@ data "github_organization_team_sync_groups" "test" { ## Argument Reference -* `q` - (Optional) Filters the results to return only those groups whose names begin with this value. +* `prefix_filter` - (Optional) Filters the results to return only those groups whose names begin with this value. ## Attributes Reference From 50ddc7e4b304bdbc7959b9ddc01f52f28161fdf9 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Mon, 2 Mar 2026 23:51:21 +0100 Subject: [PATCH 03/10] Replace prefix_filter Default with d.GetOk --- github/data_source_github_organization_team_sync_groups.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/github/data_source_github_organization_team_sync_groups.go b/github/data_source_github_organization_team_sync_groups.go index 1bb75556ed..9a81701868 100644 --- a/github/data_source_github_organization_team_sync_groups.go +++ b/github/data_source_github_organization_team_sync_groups.go @@ -17,7 +17,6 @@ func dataSourceGithubOrganizationTeamSyncGroups() *schema.Resource { "prefix_filter": { Type: schema.TypeString, Optional: true, - Default: "", Description: "Filters the results to return only those that begin with the specified value.", }, "groups": { @@ -48,14 +47,16 @@ func dataSourceGithubOrganizationTeamSyncGroupsRead(ctx context.Context, d *sche client := meta.(*Owner).v3client orgName := meta.(*Owner).name - query := d.Get("q").(string) options := &github.ListIDPGroupsOptions{ - Query: query, ListCursorOptions: github.ListCursorOptions{ PerPage: maxPerPage, }, } + 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) From d276ec292a1a5904c556acaa77c8a6072bb7bc72 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Mon, 2 Mar 2026 23:52:05 +0100 Subject: [PATCH 04/10] Change d.SetId only when the prefix_filter is set --- github/data_source_github_organization_team_sync_groups.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/github/data_source_github_organization_team_sync_groups.go b/github/data_source_github_organization_team_sync_groups.go index 9a81701868..a6fad6af72 100644 --- a/github/data_source_github_organization_team_sync_groups.go +++ b/github/data_source_github_organization_team_sync_groups.go @@ -74,7 +74,11 @@ func dataSourceGithubOrganizationTeamSyncGroupsRead(ctx context.Context, d *sche options.Page = resp.NextPageToken } - d.SetId(fmt.Sprintf("%s/github-org-team-sync-groups/%s", orgName, query)) + 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)) + } if err := d.Set("groups", groups); err != nil { return diag.Errorf("error setting groups: %v", err) } From ad7206e7f07da29a51f02354c501493802f9bba7 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Mon, 2 Mar 2026 23:52:17 +0100 Subject: [PATCH 05/10] Update docs to include both examples --- .../docs/d/organization_team_sync_groups.html.markdown | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/website/docs/d/organization_team_sync_groups.html.markdown b/website/docs/d/organization_team_sync_groups.html.markdown index b32578769e..4ab370d23b 100644 --- a/website/docs/d/organization_team_sync_groups.html.markdown +++ b/website/docs/d/organization_team_sync_groups.html.markdown @@ -12,8 +12,12 @@ Use this data source to retrieve the identity provider (IdP) groups for an organ ## Example Usage ```hcl -data "github_organization_team_sync_groups" "test" { - q = "myprefix_" +data "github_organization_team_sync_groups" "all" {} +``` + +```hcl +data "github_organization_team_sync_groups" "filtered" { + prefix_filter = "myprefix_" } ``` From 0064745027abf6eba64beee8a2430194a8abfdb2 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Thu, 5 Mar 2026 02:19:52 +0100 Subject: [PATCH 06/10] Change ID generation to use buildID --- ...ata_source_github_organization_team_sync_groups.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/github/data_source_github_organization_team_sync_groups.go b/github/data_source_github_organization_team_sync_groups.go index a6fad6af72..15c14a8b7f 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/v83/github" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -74,11 +73,15 @@ func dataSourceGithubOrganizationTeamSyncGroupsRead(ctx context.Context, d *sche options.Page = resp.NextPageToken } + idParts := []string{orgName, "team-sync-groups"} 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 = 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) } From ad18a986947fc936e64e7f3e144e84f7175f6d2e Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Thu, 5 Mar 2026 02:22:20 +0100 Subject: [PATCH 07/10] Use ConfigStateChecks in the tests --- ...thub_organization_team_sync_groups_test.go | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) 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 614062ea7b..e9dc518171 100644 --- a/github/data_source_github_organization_team_sync_groups_test.go +++ b/github/data_source_github_organization_team_sync_groups_test.go @@ -4,6 +4,9 @@ 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) { @@ -13,18 +16,18 @@ 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()), + }, }, { Config: `data "github_organization_team_sync_groups" "test" { prefix_filter = "nonexistent_prefix_" }`, - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("data.github_organization_team_sync_groups.test", "prefix_filter", "nonexistent_prefix_"), - resource.TestCheckResourceAttr("data.github_organization_team_sync_groups.test", "groups.#", "0"), - ), + 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 a6e33d8a6fc8fbf089ccfde6e6b6153f59bda5b0 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Thu, 5 Mar 2026 02:34:59 +0100 Subject: [PATCH 08/10] Add state migration for the new ID format --- ...ce_github_organization_team_sync_groups.go | 9 +++ ...organization_team_sync_groups_migration.go | 57 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 github/data_source_github_organization_team_sync_groups_migration.go diff --git a/github/data_source_github_organization_team_sync_groups.go b/github/data_source_github_organization_team_sync_groups.go index 15c14a8b7f..956cf504d6 100644 --- a/github/data_source_github_organization_team_sync_groups.go +++ b/github/data_source_github_organization_team_sync_groups.go @@ -12,6 +12,15 @@ func dataSourceGithubOrganizationTeamSyncGroups() *schema.Resource { return &schema.Resource{ ReadContext: dataSourceGithubOrganizationTeamSyncGroupsRead, + SchemaVersion: 1, + StateUpgraders: []schema.StateUpgrader{ + { + Type: dataSourceGithubOrganizationTeamSyncGroupsV0().CoreConfigSchema().ImpliedType(), + Upgrade: dataSourceGithubOrganizationTeamSyncGroupsStateUpgradeV0, + Version: 0, + }, + }, + Schema: map[string]*schema.Schema{ "prefix_filter": { Type: schema.TypeString, diff --git a/github/data_source_github_organization_team_sync_groups_migration.go b/github/data_source_github_organization_team_sync_groups_migration.go new file mode 100644 index 0000000000..7c0c7315f1 --- /dev/null +++ b/github/data_source_github_organization_team_sync_groups_migration.go @@ -0,0 +1,57 @@ +package github + +import ( + "context" + "fmt" + "log" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func dataSourceGithubOrganizationTeamSyncGroupsV0() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "groups": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "group_id": { + Type: schema.TypeString, + Computed: true, + }, + "group_name": { + Type: schema.TypeString, + Computed: true, + }, + "group_description": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + } +} + +func dataSourceGithubOrganizationTeamSyncGroupsStateUpgradeV0(ctx context.Context, rawState map[string]any, meta any) (map[string]any, error) { + log.Printf("[DEBUG] GitHub Organization Team Sync Groups State before migration: %#v", rawState) + + if rawState == nil { + return nil, fmt.Errorf("cannot migrate nil state") + } + + orgName := meta.(*Owner).name + + newID, err := buildID(orgName, "team-sync-groups") + if err != nil { + return nil, fmt.Errorf("error building migrated ID: %w", err) + } + + rawState["id"] = newID + + log.Printf("[DEBUG] GitHub Organization Team Sync Groups State after migration: %#v", rawState) + + return rawState, nil +} From 49d1e0169d3b6fecac4d90c7d1236282c9886628 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Thu, 5 Mar 2026 02:47:15 +0100 Subject: [PATCH 09/10] Use tflog instead --- ...source_github_organization_team_sync_groups_migration.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/github/data_source_github_organization_team_sync_groups_migration.go b/github/data_source_github_organization_team_sync_groups_migration.go index 7c0c7315f1..6280eed172 100644 --- a/github/data_source_github_organization_team_sync_groups_migration.go +++ b/github/data_source_github_organization_team_sync_groups_migration.go @@ -3,8 +3,8 @@ package github import ( "context" "fmt" - "log" + "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -36,7 +36,7 @@ func dataSourceGithubOrganizationTeamSyncGroupsV0() *schema.Resource { } func dataSourceGithubOrganizationTeamSyncGroupsStateUpgradeV0(ctx context.Context, rawState map[string]any, meta any) (map[string]any, error) { - log.Printf("[DEBUG] GitHub Organization Team Sync Groups State before migration: %#v", rawState) + tflog.Debug(ctx, "GitHub Organization Team Sync Groups State before migration", map[string]any{"state": rawState}) if rawState == nil { return nil, fmt.Errorf("cannot migrate nil state") @@ -51,7 +51,7 @@ func dataSourceGithubOrganizationTeamSyncGroupsStateUpgradeV0(ctx context.Contex rawState["id"] = newID - log.Printf("[DEBUG] GitHub Organization Team Sync Groups State after migration: %#v", rawState) + tflog.Debug(ctx, "GitHub Organization Team Sync Groups State after migration", map[string]any{"state": rawState}) return rawState, nil } From e21fe5d23eb58cef71c6ffe44f89606cfcc19b4b Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Fri, 6 Mar 2026 02:37:42 +0100 Subject: [PATCH 10/10] Go back to 3-part IDs --- github/data_source_github_organization_team_sync_groups.go | 6 +----- ...source_github_organization_team_sync_groups_migration.go | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/github/data_source_github_organization_team_sync_groups.go b/github/data_source_github_organization_team_sync_groups.go index 956cf504d6..48e843ee8c 100644 --- a/github/data_source_github_organization_team_sync_groups.go +++ b/github/data_source_github_organization_team_sync_groups.go @@ -82,11 +82,7 @@ func dataSourceGithubOrganizationTeamSyncGroupsRead(ctx context.Context, d *sche options.Page = resp.NextPageToken } - idParts := []string{orgName, "team-sync-groups"} - if options.Query != "" { - idParts = append(idParts, options.Query) - } - id, err := buildID(idParts...) + id, err := buildID(orgName, "team-sync-groups", options.Query) if err != nil { return diag.FromErr(err) } diff --git a/github/data_source_github_organization_team_sync_groups_migration.go b/github/data_source_github_organization_team_sync_groups_migration.go index 6280eed172..d5bc64c5f3 100644 --- a/github/data_source_github_organization_team_sync_groups_migration.go +++ b/github/data_source_github_organization_team_sync_groups_migration.go @@ -44,7 +44,7 @@ func dataSourceGithubOrganizationTeamSyncGroupsStateUpgradeV0(ctx context.Contex orgName := meta.(*Owner).name - newID, err := buildID(orgName, "team-sync-groups") + newID, err := buildID(orgName, "team-sync-groups", "") if err != nil { return nil, fmt.Errorf("error building migrated ID: %w", err) }