Skip to content

Commit

Permalink
feat: add tcp, udp, icmp protocol number validation
Browse files Browse the repository at this point in the history
  • Loading branch information
yoogledev committed Nov 29, 2022
1 parent 5d2e597 commit 04ebceb
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions ncloud/resource_ncloud_access_control_group_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ func resourceNcloudAccessControlGroupRule() *schema.Resource {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"protocol": {
Type: schema.TypeString,
Required: true,
ValidateDiagFunc: ToDiagFunc(validation.StringMatch(regexp.MustCompile(`TCP|UDP|ICMP|\b([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-2])\b`), "only TCP, UDP, ICMP and 1-252 are valid values.")),
StateFunc: ProtocolStateFunc,
Type: schema.TypeString,
Required: true,
ValidateDiagFunc: ToDiagFunc(validation.All(
validation.StringMatch(regexp.MustCompile(`TCP|UDP|ICMP|\b([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-2])\b`), "only TCP, UDP, ICMP and 1-252 are valid values."),
validation.StringNotInSlice([]string{"1", "6", "17"}, false),
)),
StateFunc: ProtocolStateFunc,
},
"port_range": {
Type: schema.TypeString,
Expand Down Expand Up @@ -74,10 +77,13 @@ func resourceNcloudAccessControlGroupRule() *schema.Resource {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"protocol": {
Type: schema.TypeString,
Required: true,
ValidateDiagFunc: ToDiagFunc(validation.StringMatch(regexp.MustCompile(`TCP|UDP|ICMP|\b([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-2])\b`), "only TCP, UDP, ICMP and 1-252 are valid values.")),
StateFunc: ProtocolStateFunc,
Type: schema.TypeString,
Required: true,
ValidateDiagFunc: ToDiagFunc(validation.All(
validation.StringMatch(regexp.MustCompile(`TCP|UDP|ICMP|\b([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-2])\b`), "only TCP, UDP, ICMP and 1-252 are valid values."),
validation.StringNotInSlice([]string{"1", "6", "17"}, false),
)),
StateFunc: ProtocolStateFunc,
},
"port_range": {
Type: schema.TypeString,
Expand Down

0 comments on commit 04ebceb

Please sign in to comment.