Skip to content

Commit

Permalink
Merge pull request #621 from vmware/allow-null-nh
Browse files Browse the repository at this point in the history
Mark ip address as optional in static route
  • Loading branch information
annakhm authored May 20, 2021
2 parents e9dbb0d + 6c0df99 commit 5fa91ce
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
- docker
language: go
go:
- "1.14.x"
- "1.15.x"

install:
# This script is used by the Travis build to install a cookie for
Expand Down
27 changes: 18 additions & 9 deletions nsxt/resource_nsxt_policy_static_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func resourceNsxtPolicyStaticRoute() *schema.Resource {
},
"ip_address": {
Type: schema.TypeString,
Required: true,
Optional: true,
Description: "Next hop gateway IP address",
ValidateFunc: validateSingleIP(),
},
Expand Down Expand Up @@ -139,12 +139,15 @@ func resourceNsxtPolicyStaticRouteCreate(d *schema.ResourceData, m interface{})
if scope != "" {
scopeList = append(scopeList, scope)
}
hopStuct := model.RouterNexthop{
hopStruct := model.RouterNexthop{
AdminDistance: &distance,
IpAddress: &ip,
Scope: scopeList,
}
nextHopsStructs = append(nextHopsStructs, hopStuct)

if len(ip) > 0 {
hopStruct.IpAddress = &ip
}
nextHopsStructs = append(nextHopsStructs, hopStruct)
}

routeStruct := model.StaticRoutes{
Expand Down Expand Up @@ -208,8 +211,12 @@ func resourceNsxtPolicyStaticRouteRead(d *schema.ResourceData, m interface{}) er
iface = scope[0]
}
nextHopMap["interface"] = iface
nextHopMap["ip_address"] = *nextHop.IpAddress
nextHopMap["admin_distance"] = *nextHop.AdminDistance
if nextHop.IpAddress != nil {
nextHopMap["ip_address"] = *nextHop.IpAddress
}
if nextHop.AdminDistance != nil {
nextHopMap["admin_distance"] = nextHop.AdminDistance
}

nextHopMaps = append(nextHopMaps, nextHopMap)
}
Expand Down Expand Up @@ -251,12 +258,14 @@ func resourceNsxtPolicyStaticRouteUpdate(d *schema.ResourceData, m interface{})
if scope != "" {
scopeList = append(scopeList, scope)
}
hopStuct := model.RouterNexthop{
hopStruct := model.RouterNexthop{
AdminDistance: &distance,
IpAddress: &ip,
Scope: scopeList,
}
nextHopsStructs = append(nextHopsStructs, hopStuct)
if len(ip) > 0 {
hopStruct.IpAddress = &ip
}
nextHopsStructs = append(nextHopsStructs, hopStruct)
}

routeStruct := model.StaticRoutes{
Expand Down
2 changes: 1 addition & 1 deletion nsxt/resource_nsxt_policy_static_route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ resource "nsxt_policy_static_route" "test" {
ip_address = "10.10.10.1"
}
next_hop {
ip_address = "11.10.10.1"
admin_distance = 2
}
tag {
scope = "scope1"
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/policy_static_route.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ The following arguments are supported:
* `gateway_path` (Required) The NSX Policy path to the Tier0 or Tier1 Gateway for this Static Route.
* `next_hop` - (Required) One or more next hops for the static route.
* `admin_distance` - (Optional) The cost associated with the next hop. Valid values are 1 - 255 and the default is 1.
* `ip_address` - (Required) The gateway address of the next hop.
* `ip_address` - (Optional) The gateway address of the next hop.
* `interface` - (Optional) The policy path to the interface associated with the static route.

## Attributes Reference
Expand Down

0 comments on commit 5fa91ce

Please sign in to comment.