Skip to content

Commit a97ce2b

Browse files
chore: add schema validations
- Add ValidateDiagFunc to required schema fields for early validation in plan phase - Add validation import to resource_github_enterprise_team_membership - This allows users to get validation errors during plan instead of apply
1 parent db3f78a commit a97ce2b

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

github/resource_github_enterprise_team.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ func resourceGithubEnterpriseTeam() *schema.Resource {
3636
Required: true,
3737
ForceNew: true,
3838
Description: "The slug of the enterprise (e.g. from the enterprise URL).",
39+
ValidateDiagFunc: validation.ToDiagFunc(validation.StringLenBetween(1, 255)),
3940
},
4041
"name": {
4142
Type: schema.TypeString,
4243
Required: true,
4344
Description: "The name of the enterprise team.",
45+
ValidateDiagFunc: validation.ToDiagFunc(validation.StringLenBetween(1, 255)),
4446
},
4547
"description": {
4648
Type: schema.TypeString,

github/resource_github_enterprise_team_membership.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
githubv3 "github.com/google/go-github/v67/github"
1111
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1212
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
13+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1314
)
1415

1516
func resourceGithubEnterpriseTeamMembership() *schema.Resource {
@@ -25,19 +26,22 @@ func resourceGithubEnterpriseTeamMembership() *schema.Resource {
2526
Required: true,
2627
ForceNew: true,
2728
Description: "The slug of the enterprise.",
29+
ValidateDiagFunc: validation.ToDiagFunc(validation.StringLenBetween(1, 255)),
2830
},
2931
"enterprise_team": {
3032
Type: schema.TypeString,
3133
Required: true,
3234
ForceNew: true,
3335
Description: "The slug or ID of the enterprise team.",
36+
ValidateDiagFunc: validation.ToDiagFunc(validation.StringLenBetween(1, 255)),
3437
},
3538
"username": {
3639
Type: schema.TypeString,
3740
Required: true,
3841
ForceNew: true,
3942
DiffSuppressFunc: caseInsensitive(),
4043
Description: "The login handle of the user.",
44+
ValidateDiagFunc: validation.ToDiagFunc(validation.StringLenBetween(1, 255)),
4145
},
4246
},
4347
}

0 commit comments

Comments
 (0)