Skip to content

Commit f83cc47

Browse files
feat: use provider owner as default for github_organization data source
When no 'name' is provided, fall back to the provider's configured owner (or the authenticated user). This makes 'name' optional. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 94f71cf commit f83cc47

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

github/data_source_github_organization.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ func dataSourceGithubOrganization() *schema.Resource {
1717
Schema: map[string]*schema.Schema{
1818
"name": {
1919
Type: schema.TypeString,
20-
Required: true,
20+
Optional: true,
21+
Computed: true,
2122
},
2223
"ignore_archived_repos": {
2324
Type: schema.TypeBool,
@@ -151,7 +152,10 @@ func dataSourceGithubOrganization() *schema.Resource {
151152
}
152153

153154
func dataSourceGithubOrganizationRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
154-
name := d.Get("name").(string)
155+
name := meta.(*Owner).name
156+
if v, ok := d.GetOk("name"); ok {
157+
name = v.(string)
158+
}
155159

156160
client4 := meta.(*Owner).v4client
157161
client3 := meta.(*Owner).v3client

website/docs/d/organization.html.markdown

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,15 @@ data "github_organization" "example" {
1717
}
1818
```
1919

20+
If `name` is omitted, the provider's configured `owner` is used:
21+
22+
```hcl
23+
data "github_organization" "example" {}
24+
```
25+
2026
## Argument Reference
2127

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

0 commit comments

Comments
 (0)