Skip to content

Commit c830136

Browse files
docs: add descriptions and plan-time validation for enterprise team org data sources/resources
- add top-level Description to enterprise team org data source and resource - add ValidateDiagFunc to required fields and drop runtime empty checks - add Description and validation to enterprise teams listing data source
1 parent 3ed45e2 commit c830136

File tree

3 files changed

+28
-28
lines changed

3 files changed

+28
-28
lines changed

github/data_source_github_enterprise_team_organizations.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,30 @@ package github
22

33
import (
44
"context"
5-
"fmt"
65
"strings"
76

87
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
98
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1010
)
1111

1212
func dataSourceGithubEnterpriseTeamOrganizations() *schema.Resource {
1313
return &schema.Resource{
14+
Description: "Lists organizations assigned to a GitHub enterprise team.",
1415
ReadContext: dataSourceGithubEnterpriseTeamOrganizationsRead,
1516

1617
Schema: map[string]*schema.Schema{
1718
"enterprise_slug": {
18-
Type: schema.TypeString,
19-
Required: true,
20-
Description: "The slug of the enterprise.",
19+
Type: schema.TypeString,
20+
Required: true,
21+
Description: "The slug of the enterprise.",
22+
ValidateDiagFunc: validation.ToDiagFunc(validation.All(validation.StringIsNotWhiteSpace, validation.StringIsNotEmpty)),
2123
},
2224
"enterprise_team": {
23-
Type: schema.TypeString,
24-
Required: true,
25-
Description: "The slug or ID of the enterprise team.",
25+
Type: schema.TypeString,
26+
Required: true,
27+
Description: "The slug or ID of the enterprise team.",
28+
ValidateDiagFunc: validation.ToDiagFunc(validation.All(validation.StringIsNotWhiteSpace, validation.StringIsNotEmpty)),
2629
},
2730
"organization_slugs": {
2831
Type: schema.TypeSet,
@@ -39,12 +42,6 @@ func dataSourceGithubEnterpriseTeamOrganizationsRead(ctx context.Context, d *sch
3942
client := meta.(*Owner).v3client
4043
enterpriseSlug := strings.TrimSpace(d.Get("enterprise_slug").(string))
4144
enterpriseTeam := strings.TrimSpace(d.Get("enterprise_team").(string))
42-
if enterpriseSlug == "" {
43-
return diag.FromErr(fmt.Errorf("enterprise_slug must not be empty"))
44-
}
45-
if enterpriseTeam == "" {
46-
return diag.FromErr(fmt.Errorf("enterprise_team must not be empty"))
47-
}
4845
orgs, err := listEnterpriseTeamOrganizations(ctx, client, enterpriseSlug, enterpriseTeam)
4946
if err != nil {
5047
return diag.FromErr(err)

github/data_source_github_enterprise_teams.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,24 @@ package github
22

33
import (
44
"context"
5-
"fmt"
65
"strings"
76

87
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
98
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1010
)
1111

1212
func dataSourceGithubEnterpriseTeams() *schema.Resource {
1313
return &schema.Resource{
14+
Description: "Lists all GitHub enterprise teams in an enterprise.",
1415
ReadContext: dataSourceGithubEnterpriseTeamsRead,
1516

1617
Schema: map[string]*schema.Schema{
1718
"enterprise_slug": {
18-
Type: schema.TypeString,
19-
Required: true,
20-
Description: "The slug of the enterprise.",
19+
Type: schema.TypeString,
20+
Required: true,
21+
Description: "The slug of the enterprise.",
22+
ValidateDiagFunc: validation.ToDiagFunc(validation.All(validation.StringIsNotWhiteSpace, validation.StringIsNotEmpty)),
2123
},
2224
"teams": {
2325
Type: schema.TypeList,
@@ -65,9 +67,6 @@ func dataSourceGithubEnterpriseTeams() *schema.Resource {
6567
func dataSourceGithubEnterpriseTeamsRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
6668
client := meta.(*Owner).v3client
6769
enterpriseSlug := strings.TrimSpace(d.Get("enterprise_slug").(string))
68-
if enterpriseSlug == "" {
69-
return diag.FromErr(fmt.Errorf("enterprise_slug must not be empty"))
70-
}
7170
teams, err := listEnterpriseTeams(ctx, client, enterpriseSlug)
7271
if err != nil {
7372
return diag.FromErr(err)

github/resource_github_enterprise_team_organizations.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ import (
1111
githubv3 "github.com/google/go-github/v67/github"
1212
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1313
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
14+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1415
)
1516

1617
func resourceGithubEnterpriseTeamOrganizations() *schema.Resource {
1718
return &schema.Resource{
19+
Description: "Manages organization assignments for a GitHub enterprise team.",
1820
CreateContext: resourceGithubEnterpriseTeamOrganizationsCreateOrUpdate,
1921
ReadContext: resourceGithubEnterpriseTeamOrganizationsRead,
2022
UpdateContext: resourceGithubEnterpriseTeamOrganizationsCreateOrUpdate,
@@ -23,16 +25,18 @@ func resourceGithubEnterpriseTeamOrganizations() *schema.Resource {
2325

2426
Schema: map[string]*schema.Schema{
2527
"enterprise_slug": {
26-
Type: schema.TypeString,
27-
Required: true,
28-
ForceNew: true,
29-
Description: "The slug of the enterprise.",
28+
Type: schema.TypeString,
29+
Required: true,
30+
ForceNew: true,
31+
Description: "The slug of the enterprise.",
32+
ValidateDiagFunc: validation.ToDiagFunc(validation.All(validation.StringIsNotWhiteSpace, validation.StringIsNotEmpty)),
3033
},
3134
"enterprise_team": {
32-
Type: schema.TypeString,
33-
Required: true,
34-
ForceNew: true,
35-
Description: "The slug or ID of the enterprise team.",
35+
Type: schema.TypeString,
36+
Required: true,
37+
ForceNew: true,
38+
Description: "The slug or ID of the enterprise team.",
39+
ValidateDiagFunc: validation.ToDiagFunc(validation.All(validation.StringIsNotWhiteSpace, validation.StringIsNotEmpty)),
3640
},
3741
"organization_slugs": {
3842
Type: schema.TypeSet,

0 commit comments

Comments
 (0)