Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark ip address as optional in static route #621

Merged
merged 2 commits into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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