Skip to content

Commit 11ac5ac

Browse files
Validate experes_at during plan
1 parent b1a9c53 commit 11ac5ac

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

gitlab/resource_gitlab_group_membership.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ func resourceGitlabGroupMembership() *schema.Resource {
4040
Required: true,
4141
},
4242
"expires_at": {
43-
Type: schema.TypeString, // Format YYYY-MM-DD
44-
Optional: true,
43+
Type: schema.TypeString, // Format YYYY-MM-DD
44+
ValidateFunc: validateDateFunc(),
45+
Optional: true,
4546
},
4647
},
4748
}

gitlab/resource_gitlab_project_membership.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,6 @@ func resourceGitlabProjectMembership() *schema.Resource {
4444
}
4545
}
4646

47-
var accessLevelID = map[string]gitlab.AccessLevelValue{
48-
"guest": gitlab.GuestPermissions,
49-
"reporter": gitlab.ReporterPermissions,
50-
"developer": gitlab.DeveloperPermissions,
51-
"master": gitlab.MasterPermissions,
52-
"owner": gitlab.OwnerPermission,
53-
}
54-
5547
func resourceGitlabProjectMembershipCreate(d *schema.ResourceData, meta interface{}) error {
5648
client := meta.(*gitlab.Client)
5749

gitlab/util.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/xanzy/go-gitlab"
88
"regexp"
99
"strings"
10+
"time"
1011
)
1112

1213
// copied from ../github/util.go
@@ -28,6 +29,18 @@ func validateValueFunc(values []string) schema.SchemaValidateFunc {
2829
}
2930
}
3031

32+
func validateDateFunc() schema.SchemaValidateFunc {
33+
return func(v interface{}, k string) (we []string, errors []error) {
34+
value := v.(string)
35+
//add zero hours and let time figure out correctness
36+
_, e := time.Parse(time.RFC3339, value+"T00:00:00Z")
37+
if e != nil {
38+
errors = append(errors, fmt.Errorf("%s is not valid for format YYYY-MM-DD", value))
39+
}
40+
return
41+
}
42+
}
43+
3144
func stringToVisibilityLevel(s string) *gitlab.VisibilityValue {
3245
lookup := map[string]gitlab.VisibilityValue{
3346
"private": gitlab.PrivateVisibility,
@@ -75,3 +88,11 @@ func parseTwoPartID(id string) (string, string, error) {
7588
func buildTwoPartID(a, b *string) string {
7689
return fmt.Sprintf("%s:%s", *a, *b)
7790
}
91+
92+
var accessLevelID = map[string]gitlab.AccessLevelValue{
93+
"guest": gitlab.GuestPermissions,
94+
"reporter": gitlab.ReporterPermissions,
95+
"developer": gitlab.DeveloperPermissions,
96+
"master": gitlab.MasterPermissions,
97+
"owner": gitlab.OwnerPermission,
98+
}

0 commit comments

Comments
 (0)