Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions docs/data-sources/organization_team_sync_groups.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,45 @@
---
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

```terraform
data "github_organization_team_sync_groups" "test" {}
# Retrieve all IdP groups for the organization.
data "github_organization_team_sync_groups" "all" {}
```

## Attributes Reference
```terraform
# Retrieve IdP groups whose names begin with a given prefix.
data "github_organization_team_sync_groups" "filtered" {
prefix_filter = "myprefix_"
}
```

- `groups` - An Array of GitHub Identity Provider Groups. Each `group` block consists of the fields documented below.
<!-- schema generated by tfplugindocs -->
## Schema

---
### Optional

- `prefix_filter` (String) Filters the results to return only those that begin with the specified value.

### 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.
<a id="nestedatt--groups"></a>
### 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)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Retrieve all IdP groups for the organization.
data "github_organization_team_sync_groups" "all" {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Retrieve IdP groups whose names begin with a given prefix.
data "github_organization_team_sync_groups" "filtered" {
prefix_filter = "myprefix_"
}

This file was deleted.

22 changes: 20 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/v89/github"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand All @@ -12,8 +11,14 @@ 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": {
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.

},
"groups": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -49,6 +54,11 @@ func dataSourceGithubOrganizationTeamSyncGroupsRead(ctx context.Context, d *sche
},
}

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

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

d.SetId(fmt.Sprintf("%s/github-org-team-sync-groups", orgName))
query := options.Query
if query == "" {
query = "*"
}
id, err := buildID(orgName, 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)
}
Expand Down
49 changes: 42 additions & 7 deletions github/data_source_github_organization_team_sync_groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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)),
},
},
},
})
Expand Down
27 changes: 0 additions & 27 deletions templates/data-sources/organization_team_sync_groups.md.tmpl

This file was deleted.

Loading