-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
validate.go
31 lines (24 loc) · 867 Bytes
/
validate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package provider
import (
"fmt"
"regexp"
"time"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
// validAssumeRoleDuration validates a string can be parsed as a valid time.Duration
// and is within a minimum of 15 minutes and maximum of 12 hours
func validAssumeRoleDuration(v interface{}, k string) (ws []string, errors []error) {
duration, err := time.ParseDuration(v.(string))
if err != nil {
errors = append(errors, fmt.Errorf("%q cannot be parsed as a duration: %w", k, err))
return
}
if duration.Minutes() < 15 || duration.Hours() > 12 {
errors = append(errors, fmt.Errorf("duration %q must be between 15 minutes (15m) and 12 hours (12h), inclusive", k))
}
return
}
var validAssumeRoleSessionName = validation.All(
validation.StringLenBetween(2, 64),
validation.StringMatch(regexp.MustCompile(`[\w+=,.@\-]*`), ""),
)