diff --git a/provider/lib.go b/provider/lib.go index 2c13464..5f63c9f 100644 --- a/provider/lib.go +++ b/provider/lib.go @@ -350,6 +350,12 @@ func existsInRange(needle int, min, max int) bool { return false } +func validStringLength(needle string, min, max int) bool { + length := len(needle) + + return length >= min && length <= max +} + func expandRuleConditions(conditionsResource *schema.Set) []sigsci.Condition { var conditions []sigsci.Condition for _, genericElement := range conditionsResource.List() { diff --git a/provider/resource_corp_integration.go b/provider/resource_corp_integration.go index d252063..1be5914 100644 --- a/provider/resource_corp_integration.go +++ b/provider/resource_corp_integration.go @@ -25,7 +25,7 @@ func resourceCorpIntegration() *schema.Resource { ForceNew: true, ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) { if !existsInString(val.(string), "mailingList", "slack", "microsoftTeams") { - return nil, []error{fmt.Errorf(`"received type %q is invalid. should be "mailingList", "slack", or "microsoftTeams"`, val.(string))} + return nil, []error{fmt.Errorf(`received type %q is invalid. should be "mailingList", "slack", or "microsoftTeams"`, val.(string))} } return nil, nil }, diff --git a/provider/resource_corp_list.go b/provider/resource_corp_list.go index c9e8782..d35305d 100644 --- a/provider/resource_corp_list.go +++ b/provider/resource_corp_list.go @@ -22,17 +22,35 @@ func resourceCorpList() *schema.Resource { Description: "Descriptive list name", Required: true, ForceNew: true, + ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) { + if !validStringLength(val.(string), 3, 32) { + return nil, []error{fmt.Errorf(`received name %q is invalid. should be min len 3, max len 32`, val.(string))} + } + return nil, nil + }, }, "type": { Type: schema.TypeString, Description: "List types (string, ip, country, wildcard, signal)", Required: true, ForceNew: true, + ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) { + if !existsInString(val.(string), "string", "ip", "country", "wildcard", "signal") { + return nil, []error{fmt.Errorf(`received type %q is invalid. should be "string", "ip", "country", "wildcard" or "signal"`, val.(string))} + } + return nil, nil + }, }, "description": { Type: schema.TypeString, Description: "Optional list description", Optional: true, + ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) { + if !validStringLength(val.(string), 0, 140) { + return nil, []error{fmt.Errorf(`received description %q is invalid. should be max len 140`, val.(string))} + } + return nil, nil + }, }, "entries": { Type: schema.TypeSet,