Skip to content

Commit

Permalink
Merge pull request #1475 from vmware/dhcp-relay-interface
Browse files Browse the repository at this point in the history
Add dhcp relay path to T0 and T1 interface objects
  • Loading branch information
annakhm authored Dec 5, 2024
2 parents 319d98f + 18983b9 commit c1ccf21
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 16 deletions.
14 changes: 13 additions & 1 deletion nsxt/resource_nsxt_policy_tier0_gateway_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ func resourceNsxtPolicyTier0GatewayInterface() *schema.Resource {
ForceNew: true,
ValidateFunc: validatePolicyPath(),
},
"ospf": getGatewayInterfaceOspfSchema(),
"ospf": getGatewayInterfaceOspfSchema(),
"dhcp_relay_path": getPolicyPathSchema(false, false, "Policy path for DHCP relay config"),
},
}
}
Expand Down Expand Up @@ -241,6 +242,7 @@ func resourceNsxtPolicyTier0GatewayInterfaceCreate(d *schema.ResourceData, m int

segmentPath := d.Get("segment_path").(string)
objSitePath := d.Get("site_path").(string)
dhcpRelayPath := d.Get("dhcp_relay_path").(string)
ifType := d.Get("type").(string)
if len(segmentPath) == 0 && ifType != model.Tier0Interface_TYPE_LOOPBACK {
// segment_path in required for all interfaces other than loopback
Expand Down Expand Up @@ -322,6 +324,10 @@ func resourceNsxtPolicyTier0GatewayInterfaceCreate(d *schema.ResourceData, m int
obj.SegmentPath = &segmentPath
}

if len(dhcpRelayPath) > 0 {
obj.DhcpRelayPath = &dhcpRelayPath
}

if mtu > 0 {
obj.Mtu = &mtu
}
Expand Down Expand Up @@ -408,6 +414,7 @@ func resourceNsxtPolicyTier0GatewayInterfaceRead(d *schema.ResourceData, m inter
d.Set("segment_path", obj.SegmentPath)
d.Set("edge_node_path", obj.EdgePath)
d.Set("type", obj.Type_)
d.Set("dhcp_relay_path", obj.DhcpRelayPath)

if obj.Ipv6ProfilePaths != nil {
d.Set("ipv6_ndra_profile_path", obj.Ipv6ProfilePaths[0]) // only one supported for now
Expand Down Expand Up @@ -468,6 +475,7 @@ func resourceNsxtPolicyTier0GatewayInterfaceUpdate(d *schema.ResourceData, m int

displayName := d.Get("display_name").(string)
description := d.Get("description").(string)
dhcpRelayPath := d.Get("dhcp_relay_path").(string)
tags := getPolicyTagsFromSchema(d)
interfaceSubnetList := getGatewayInterfaceSubnetList(d)
segmentPath := d.Get("segment_path").(string)
Expand All @@ -493,6 +501,10 @@ func resourceNsxtPolicyTier0GatewayInterfaceUpdate(d *schema.ResourceData, m int
obj.Mtu = &mtu
}

if len(dhcpRelayPath) > 0 || d.HasChange("dhcp_relay_path") {
obj.DhcpRelayPath = &dhcpRelayPath
}

if edgePath != "" {
obj.EdgePath = &edgePath
}
Expand Down
22 changes: 15 additions & 7 deletions nsxt/resource_nsxt_policy_tier0_gateway_interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ func TestAccResourceNsxtPolicyTier0GatewayInterface_withID(t *testing.T) {
resource.TestCheckResourceAttr(testResourceName, "ip_addresses.#", "1"),
resource.TestCheckResourceAttr(testResourceName, "ip_addresses.0", ipAddress),
resource.TestCheckResourceAttr(testResourceName, "tag.#", "0"),
resource.TestCheckResourceAttrSet(testResourceName, "dhcp_relay_path"),
resource.TestCheckResourceAttrSet(testResourceName, "segment_path"),
resource.TestCheckResourceAttrSet(testResourceName, "gateway_path"),
resource.TestCheckResourceAttrSet(testResourceName, "path"),
Expand All @@ -390,6 +391,7 @@ func TestAccResourceNsxtPolicyTier0GatewayInterface_withID(t *testing.T) {
resource.TestCheckResourceAttr(testResourceName, "ip_addresses.#", "2"),
resource.TestCheckResourceAttr(testResourceName, "ip_addresses.0", ipAddress),
resource.TestCheckResourceAttr(testResourceName, "ip_addresses.1", ipv6Address),
resource.TestCheckResourceAttrSet(testResourceName, "dhcp_relay_path"),
resource.TestCheckResourceAttrSet(testResourceName, "segment_path"),
resource.TestCheckResourceAttrSet(testResourceName, "gateway_path"),
resource.TestCheckResourceAttrSet(testResourceName, "path"),
Expand Down Expand Up @@ -726,20 +728,26 @@ resource "nsxt_policy_tier0_gateway_interface" "test" {

func testAccNsxtPolicyTier0InterfaceTemplateWithID(name string, subnet string) string {
return testAccNsxtPolicyGatewayInterfaceDeps("11", false) + fmt.Sprintf(`
resource "nsxt_policy_dhcp_relay" "test" {
display_name = "test"
server_addresses = ["10.203.34.15"]
}
resource "nsxt_policy_tier0_gateway" "test" {
display_name = "%s"
ha_mode = "ACTIVE_STANDBY"
%s
}
resource "nsxt_policy_tier0_gateway_interface" "test" {
nsx_id = "test"
display_name = "%s"
type = "SERVICE"
description = "Acceptance Test"
gateway_path = nsxt_policy_tier0_gateway.test.path
segment_path = nsxt_policy_vlan_segment.test.path
subnets = ["%s"]
nsx_id = "test"
display_name = "%s"
type = "SERVICE"
description = "Acceptance Test"
gateway_path = nsxt_policy_tier0_gateway.test.path
segment_path = nsxt_policy_vlan_segment.test.path
subnets = ["%s"]
dhcp_relay_path = nsxt_policy_dhcp_relay.test.path
%s
}`, nsxtPolicyTier0GatewayName, testAccNsxtPolicyTier0EdgeClusterTemplate(), name, subnet, testAccNsxtPolicyTier0InterfaceSiteTemplate()) +
testAccNsxtPolicyTier0InterfaceRealizationTemplate()
Expand Down
12 changes: 12 additions & 0 deletions nsxt/resource_nsxt_policy_tier1_gateway_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func resourceNsxtPolicyTier1GatewayInterface() *schema.Resource {
ForceNew: true,
ValidateFunc: validatePolicyPath(),
},
"dhcp_relay_path": getPolicyPathSchema(false, false, "Policy path for DHCP relay config"),
},
}
}
Expand Down Expand Up @@ -136,6 +137,7 @@ func resourceNsxtPolicyTier1GatewayInterfaceCreate(d *schema.ResourceData, m int
displayName := d.Get("display_name").(string)
description := d.Get("description").(string)
segmentPath := d.Get("segment_path").(string)
dhcpRelayPath := d.Get("dhcp_relay_path").(string)
tags := getPolicyTagsFromSchema(d)
interfaceSubnetList := getGatewayInterfaceSubnetList(d)
var ipv6ProfilePaths []string
Expand All @@ -153,6 +155,10 @@ func resourceNsxtPolicyTier1GatewayInterfaceCreate(d *schema.ResourceData, m int
Ipv6ProfilePaths: ipv6ProfilePaths,
}

if len(dhcpRelayPath) > 0 {
obj.DhcpRelayPath = &dhcpRelayPath
}

if mtu > 0 {
obj.Mtu = &mtu
}
Expand Down Expand Up @@ -229,6 +235,7 @@ func resourceNsxtPolicyTier1GatewayInterfaceRead(d *schema.ResourceData, m inter
d.Set("path", obj.Path)
d.Set("revision", obj.Revision)
d.Set("segment_path", obj.SegmentPath)
d.Set("dhcp_relay_path", obj.DhcpRelayPath)
if obj.Ipv6ProfilePaths != nil {
d.Set("ipv6_ndra_profile_path", obj.Ipv6ProfilePaths[0]) // only one supported for now
}
Expand Down Expand Up @@ -269,6 +276,7 @@ func resourceNsxtPolicyTier1GatewayInterfaceUpdate(d *schema.ResourceData, m int
tags := getPolicyTagsFromSchema(d)
interfaceSubnetList := getGatewayInterfaceSubnetList(d)
segmentPath := d.Get("segment_path").(string)
dhcpRelayPath := d.Get("dhcp_relay_path").(string)
var ipv6ProfilePaths []string
if d.Get("ipv6_ndra_profile_path").(string) != "" {
ipv6ProfilePaths = append(ipv6ProfilePaths, d.Get("ipv6_ndra_profile_path").(string))
Expand All @@ -285,6 +293,10 @@ func resourceNsxtPolicyTier1GatewayInterfaceUpdate(d *schema.ResourceData, m int
Revision: &revision,
}

if len(dhcpRelayPath) > 0 || d.HasChange("dhcp_relay_path") {
obj.DhcpRelayPath = &dhcpRelayPath
}

if mtu > 0 {
obj.Mtu = &mtu
}
Expand Down
24 changes: 16 additions & 8 deletions nsxt/resource_nsxt_policy_tier1_gateway_interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func TestAccResourceNsxtPolicyTier1GatewayInterface_withID(t *testing.T) {
resource.TestCheckResourceAttr(testResourceName, "description", "Acceptance Test"),
resource.TestCheckResourceAttr(testResourceName, "subnets.#", "1"),
resource.TestCheckResourceAttr(testResourceName, "subnets.0", subnet),
resource.TestCheckResourceAttrSet(testResourceName, "dhcp_relay_path"),
resource.TestCheckResourceAttr(testResourceName, "urpf_mode", "NONE"),
resource.TestCheckResourceAttr(testResourceName, "tag.#", "0"),
resource.TestCheckResourceAttrSet(testResourceName, "segment_path"),
Expand All @@ -147,6 +148,7 @@ func TestAccResourceNsxtPolicyTier1GatewayInterface_withID(t *testing.T) {
resource.TestCheckResourceAttr(testResourceName, "subnets.#", "2"),
resource.TestCheckResourceAttr(testResourceName, "subnets.0", subnet),
resource.TestCheckResourceAttr(testResourceName, "subnets.1", ipv6Subnet),
resource.TestCheckResourceAttrSet(testResourceName, "dhcp_relay_path"),
resource.TestCheckResourceAttr(testResourceName, "urpf_mode", "NONE"),
resource.TestCheckResourceAttrSet(testResourceName, "segment_path"),
resource.TestCheckResourceAttrSet(testResourceName, "gateway_path"),
Expand Down Expand Up @@ -478,19 +480,25 @@ resource "nsxt_policy_tier1_gateway_interface" "test" {

func testAccNsxtPolicyTier1InterfaceTemplateWithID(name string, subnet string) string {
return testAccNsxtPolicyGatewayInterfaceDeps("11", false) + fmt.Sprintf(`
resource "nsxt_policy_dhcp_relay" "test" {
display_name = "test"
server_addresses = ["10.203.34.15"]
}
resource "nsxt_policy_tier1_gateway" "test" {
display_name = "%s"
display_name = "%s"
%s
}
resource "nsxt_policy_tier1_gateway_interface" "test" {
nsx_id = "test"
display_name = "%s"
description = "Acceptance Test"
gateway_path = nsxt_policy_tier1_gateway.test.path
segment_path = nsxt_policy_vlan_segment.test.path
subnets = ["%s"]
urpf_mode = "NONE"
nsx_id = "test"
display_name = "%s"
description = "Acceptance Test"
gateway_path = nsxt_policy_tier1_gateway.test.path
segment_path = nsxt_policy_vlan_segment.test.path
subnets = ["%s"]
urpf_mode = "NONE"
dhcp_relay_path = nsxt_policy_dhcp_relay.test.path
%s
}`, nsxtPolicyTier1GatewayName, testAccNsxtPolicyTier0EdgeClusterTemplate(), name, subnet, testAccNsxtPolicyTier0InterfaceSiteTemplate()) +
testAccNextPolicyTier1InterfaceRealizationTemplate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ The following arguments are supported:
* `edge_node_path` - (Optional) Path of edge node for this interface, relevant for interfaces of type `EXTERNAL`.
* `mtu` - (Optional) Maximum Transmission Unit for this interface.
* `ipv6_ndra_profile_path` - (Optional) IPv6 NDRA profile to be associated with this interface.
* `dhcp_relay_path` - (Optional) DHCP relay path to be associated with this interface.
* `enable_pim` - (Optional) Flag to enable Protocol Independent Multicast, relevant only for interfaces of type `EXTERNAL`. This attribute will always be `false` for other interface types. This attribute is supported with NSX 3.0.0 onwards, and only for local managers.
* `access_vlan_id`- (Optional) Access VLAN ID, relevant only for VRF interfaces. This attribute is supported with NSX 3.0.0 onwards.
* `urpf_mode` - (Optional) Unicast Reverse Path Forwarding mode, one of `NONE`, `STRICT`. Default is `STRICT`. This attribute is supported with NSX 3.0.0 onwards.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ The following arguments are supported:
* `subnets` - (Required) list of Ip Addresses/Prefixes in CIDR format, to be associated with this interface.
* `mtu` - (Optional) Maximum Transmission Unit for this interface.
* `ipv6_ndra_profile_path` - (Optional) IPv6 NDRA profile to be associated with this interface.
* `dhcp_relay_path` - (Optional) DHCP relay path to be associated with this interface.
* `urpf_mode` - (Optional) Unicast Reverse Path Forwarding mode, one of `NONE`, `STRICT`. Default is `STRICT`. This attribute is supported with NSX 3.0.0 onwards.
* `site_path` - (Required for global manager only) Path of the site the Tier1 edge cluster belongs to. This configuration is required for global manager only. `path` field of the existing `nsxt_policy_site` can be used here.

Expand Down

0 comments on commit c1ccf21

Please sign in to comment.