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
8 changes: 6 additions & 2 deletions github/data_source_github_organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ func dataSourceGithubOrganization() *schema.Resource {
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Optional: true,
Computed: true,
},
"ignore_archived_repos": {
Type: schema.TypeBool,
Expand Down Expand Up @@ -151,7 +152,10 @@ func dataSourceGithubOrganization() *schema.Resource {
}

func dataSourceGithubOrganizationRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
name := d.Get("name").(string)
name := meta.(*Owner).name
if v, ok := d.GetOk("name"); ok {
name = v.(string)
}

client4 := meta.(*Owner).v4client
client3 := meta.(*Owner).v3client
Expand Down
23 changes: 23 additions & 0 deletions github/data_source_github_organization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,32 @@ import (

"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"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 TestAccGithubOrganizationDataSource(t *testing.T) {
t.Run("uses provider owner when name is not set", func(t *testing.T) {
config := `data "github_organization" "test" {}`

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessHasOrgs(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue("data.github_organization.test", tfjsonpath.New("login"), knownvalue.StringExact(testAccConf.owner)),
statecheck.ExpectKnownValue("data.github_organization.test", tfjsonpath.New("orgname"), knownvalue.StringExact(testAccConf.owner)),
statecheck.ExpectKnownValue("data.github_organization.test", tfjsonpath.New("node_id"), knownvalue.NotNull()),
statecheck.ExpectKnownValue("data.github_organization.test", tfjsonpath.New("plan"), knownvalue.NotNull()),
},
},
},
})
})

t.Run("queries for an organization without error", func(t *testing.T) {
config := fmt.Sprintf(`
data "github_organization" "test" {
Expand Down
8 changes: 7 additions & 1 deletion website/docs/d/organization.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ data "github_organization" "example" {
}
```

If `name` is omitted, the provider's configured `owner` is used:

```hcl
data "github_organization" "example" {}
```

## Argument Reference

* `name` - (Required) The name of the organization.
* `name` - (Optional) The name of the organization. Defaults to the provider's configured `owner`.
* `ignore_archived_repos` - (Optional) Whether or not to include archived repos in the `repositories` list. Defaults to `false`.
* `summary_only` - (Optional) Exclude the repos, members and other attributes from the returned result. Defaults to `false`.

Expand Down