Skip to content

Commit 34b4993

Browse files
docs: validate enterprise team membership fields at plan time
- move required field emptiness checks into ValidateDiagFunc - remove redundant runtime empty checks in Read - keep behavior unchanged, but surface errors during plan
1 parent 0bf1d93 commit 34b4993

1 file changed

Lines changed: 13 additions & 19 deletions

File tree

github/data_source_github_enterprise_team_membership.go

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ 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 dataSourceGithubEnterpriseTeamMembership() *schema.Resource {
@@ -15,19 +15,22 @@ func dataSourceGithubEnterpriseTeamMembership() *schema.Resource {
1515

1616
Schema: map[string]*schema.Schema{
1717
"enterprise_slug": {
18-
Type: schema.TypeString,
19-
Required: true,
20-
Description: "The slug of the enterprise.",
18+
Type: schema.TypeString,
19+
Required: true,
20+
Description: "The slug of the enterprise.",
21+
ValidateDiagFunc: validation.ToDiagFunc(validation.All(validation.StringIsNotWhiteSpace, validation.StringIsNotEmpty)),
2122
},
2223
"enterprise_team": {
23-
Type: schema.TypeString,
24-
Required: true,
25-
Description: "The slug or ID of the enterprise team.",
24+
Type: schema.TypeString,
25+
Required: true,
26+
Description: "The slug or ID of the enterprise team.",
27+
ValidateDiagFunc: validation.ToDiagFunc(validation.All(validation.StringIsNotWhiteSpace, validation.StringIsNotEmpty)),
2628
},
2729
"username": {
28-
Type: schema.TypeString,
29-
Required: true,
30-
Description: "The GitHub username.",
30+
Type: schema.TypeString,
31+
Required: true,
32+
Description: "The GitHub username.",
33+
ValidateDiagFunc: validation.ToDiagFunc(validation.All(validation.StringIsNotWhiteSpace, validation.StringIsNotEmpty)),
3134
},
3235
"role": {
3336
Type: schema.TypeString,
@@ -53,15 +56,6 @@ func dataSourceGithubEnterpriseTeamMembershipRead(ctx context.Context, d *schema
5356
enterpriseSlug := strings.TrimSpace(d.Get("enterprise_slug").(string))
5457
enterpriseTeam := strings.TrimSpace(d.Get("enterprise_team").(string))
5558
username := strings.TrimSpace(d.Get("username").(string))
56-
if enterpriseSlug == "" {
57-
return diag.FromErr(fmt.Errorf("enterprise_slug must not be empty"))
58-
}
59-
if enterpriseTeam == "" {
60-
return diag.FromErr(fmt.Errorf("enterprise_team must not be empty"))
61-
}
62-
if username == "" {
63-
return diag.FromErr(fmt.Errorf("username must not be empty"))
64-
}
6559
m, resp, err := getEnterpriseTeamMembershipDetails(ctx, client, enterpriseSlug, enterpriseTeam, username)
6660
if err != nil {
6761
return diag.FromErr(err)

0 commit comments

Comments
 (0)