Skip to content

Commit

Permalink
Merge pull request #666 from vmware/fix-as-path-validation
Browse files Browse the repository at this point in the history
Fix AS path validation in route map
  • Loading branch information
annakhm authored Sep 8, 2021
2 parents 422afd8 + ece9277 commit dd35509
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion nsxt/resource_nsxt_policy_gateway_route_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func getPolicyRouteMapEntrySchema() *schema.Resource {
"as_path_prepend": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateASPlainOrDot,
ValidateFunc: validateASPath,
Description: "Autonomous System (AS) path prepend to influence route selection",
},
"community": {
Expand Down
2 changes: 1 addition & 1 deletion nsxt/resource_nsxt_policy_gateway_route_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ resource "nsxt_policy_gateway_route_map" "test" {
}
set {
as_path_prepend = "12.998"
as_path_prepend = "100 100"
community = "11:22"
local_preference = 1122
med = 120
Expand Down
15 changes: 15 additions & 0 deletions nsxt/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,21 @@ func validateASPlainOrDot(i interface{}, k string) (s []string, es []error) {
return
}

func validateASPath(i interface{}, k string) (s []string, es []error) {
v, ok := i.(string)
if !ok {
es = append(es, fmt.Errorf("String is expected, got %s", v))
return
}

tokens := strings.Split(v, " ")
for _, token := range tokens {
s, es = validateASPlainOrDot(token, k)
}

return
}

func validatePolicyBGPCommunity(i interface{}, k string) (s []string, es []error) {
v, ok := i.(string)
if !ok {
Expand Down

0 comments on commit dd35509

Please sign in to comment.