From 7cee6a087c06caf2fe543c5f3161c681a5e22d68 Mon Sep 17 00:00:00 2001 From: Anna Khmelnitsky Date: Tue, 18 May 2021 20:26:46 +0000 Subject: [PATCH 1/2] Mark ip address as optional in static route As platform allows this, the provider should follow suite. --- nsxt/resource_nsxt_policy_static_route.go | 27 ++++++++++++------- .../resource_nsxt_policy_static_route_test.go | 2 +- .../docs/r/policy_static_route.html.markdown | 2 +- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/nsxt/resource_nsxt_policy_static_route.go b/nsxt/resource_nsxt_policy_static_route.go index 400fb9ae9..72fa81aa9 100644 --- a/nsxt/resource_nsxt_policy_static_route.go +++ b/nsxt/resource_nsxt_policy_static_route.go @@ -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(), }, @@ -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{ @@ -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) } @@ -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{ diff --git a/nsxt/resource_nsxt_policy_static_route_test.go b/nsxt/resource_nsxt_policy_static_route_test.go index 2898c03b5..8dd1bc886 100644 --- a/nsxt/resource_nsxt_policy_static_route_test.go +++ b/nsxt/resource_nsxt_policy_static_route_test.go @@ -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" diff --git a/website/docs/r/policy_static_route.html.markdown b/website/docs/r/policy_static_route.html.markdown index 6c59c7340..402f8014a 100644 --- a/website/docs/r/policy_static_route.html.markdown +++ b/website/docs/r/policy_static_route.html.markdown @@ -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 From 6c0df99e4cf063baae2d4cfc386ba38d776622ca Mon Sep 17 00:00:00 2001 From: Anna Khmelnitsky Date: Tue, 18 May 2021 20:36:53 +0000 Subject: [PATCH 2/2] Bump up go version in travis CI --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ebadb89b1..d3c84e2f7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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