Skip to content

Commit 62fa8c9

Browse files
authored
Merge pull request #1166 from ksamoray/tnp_sub_config
Set sub-config in transport_node_profile resource
2 parents b2b525f + aa79d0f commit 62fa8c9

File tree

5 files changed

+255
-90
lines changed

5 files changed

+255
-90
lines changed

nsxt/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ func Provider() *schema.Provider {
483483
"nsxt_policy_site": resourceNsxtPolicySite(),
484484
"nsxt_policy_global_manager": resourceNsxtPolicyGlobalManager(),
485485
"nsxt_policy_metadata_proxy": resourceNsxtPolicyMetadataProxy(),
486+
"nsxt_edge_transport_node_rtep": resourceNsxtEdgeTransportNodeRTEP(),
486487
},
487488

488489
ConfigureFunc: providerConfigure,

nsxt/resource_nsxt_edge_transport_node.go

Lines changed: 14 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -117,34 +117,6 @@ func resourceNsxtEdgeTransportNode() *schema.Resource {
117117
Type: schema.TypeString,
118118
},
119119
},
120-
121-
"remote_tunnel_endpoint": {
122-
Type: schema.TypeList,
123-
Description: "Configuration for a remote tunnel endpoint",
124-
MaxItems: 1,
125-
Optional: true,
126-
Elem: &schema.Resource{
127-
Schema: map[string]*schema.Schema{
128-
"host_switch_name": {
129-
Type: schema.TypeString,
130-
Description: "The host switch name to be used for the remote tunnel endpoint",
131-
Required: true,
132-
},
133-
"ip_assignment": getIPAssignmentSchema(),
134-
"named_teaming_policy": {
135-
Type: schema.TypeString,
136-
Description: "The named teaming policy to be used by the remote tunnel endpoint",
137-
Optional: true,
138-
},
139-
"rtep_vlan": {
140-
Type: schema.TypeInt,
141-
Description: "VLAN id for remote tunnel endpoint",
142-
Required: true,
143-
ValidateFunc: validation.IntBetween(0, 4094),
144-
},
145-
},
146-
},
147-
},
148120
},
149121
}
150122
}
@@ -463,7 +435,7 @@ func getStandardHostSwitchSchema(nodeType string) *schema.Schema {
463435
Computed: true,
464436
},
465437
"host_switch_profile": getHostSwitchProfileIDsSchema(),
466-
"ip_assignment": getIPAssignmentSchema(),
438+
"ip_assignment": getIPAssignmentSchema(true),
467439
"pnic": {
468440
Type: schema.TypeList,
469441
Optional: true,
@@ -541,7 +513,7 @@ func getStandardHostSwitchSchema(nodeType string) *schema.Schema {
541513
Description: "The host switch id. This ID will be used to reference a host switch",
542514
},
543515
"host_switch_profile": getHostSwitchProfileIDsSchema(),
544-
"ip_assignment": getIPAssignmentSchema(),
516+
"ip_assignment": getIPAssignmentSchema(false),
545517
"uplink": getUplinksSchema(),
546518
},
547519
},
@@ -645,12 +617,13 @@ func getHostSwitchProfileIDsSchema() *schema.Schema {
645617
}
646618
}
647619

648-
func getIPAssignmentSchema() *schema.Schema {
620+
func getIPAssignmentSchema(required bool) *schema.Schema {
649621
return &schema.Schema{
650622
Type: schema.TypeList,
651623
Description: "Specification for IPs to be used with host switch virtual tunnel endpoints",
652624
MaxItems: 1,
653-
Required: true,
625+
Required: required,
626+
Optional: !required,
654627
Elem: &schema.Resource{
655628
Schema: map[string]*schema.Schema{
656629
"assigned_by_dhcp": {
@@ -745,18 +718,13 @@ func getTransportNodeFromSchema(d *schema.ResourceData) (*model.TransportNode, e
745718
}
746719
nodeDeploymentInfo := dataValue.(*data.StructValue)
747720

748-
remoteTunnelEndpoint, err := getRemoteTunnelEndpointFromSchema(d)
749-
if err != nil {
750-
return nil, fmt.Errorf("failed to create Transport Node: %v", err)
751-
}
752721
obj := model.TransportNode{
753-
Description: &description,
754-
DisplayName: &displayName,
755-
Tags: tags,
756-
FailureDomainId: &failureDomain,
757-
HostSwitchSpec: hostSwitchSpec,
758-
NodeDeploymentInfo: nodeDeploymentInfo,
759-
RemoteTunnelEndpoint: remoteTunnelEndpoint,
722+
Description: &description,
723+
DisplayName: &displayName,
724+
Tags: tags,
725+
FailureDomainId: &failureDomain,
726+
HostSwitchSpec: hostSwitchSpec,
727+
NodeDeploymentInfo: nodeDeploymentInfo,
760728
}
761729

762730
return &obj, nil
@@ -782,27 +750,6 @@ func resourceNsxtEdgeTransportNodeCreate(d *schema.ResourceData, m interface{})
782750
return resourceNsxtEdgeTransportNodeRead(d, m)
783751
}
784752

785-
func getRemoteTunnelEndpointFromSchema(d *schema.ResourceData) (*model.TransportNodeRemoteTunnelEndpointConfig, error) {
786-
for _, r := range d.Get("remote_tunnel_endpoint").([]interface{}) {
787-
rte := r.(map[string]interface{})
788-
hostSwitchName := rte["host_switch_name"].(string)
789-
ipAssignment, err := getIPAssignmentFromSchema(rte["ip_assignment"].([]interface{}))
790-
if err != nil {
791-
return nil, err
792-
}
793-
namedTeamingPolicy := rte["named_teaming_policy"].(string)
794-
rtepVlan := int64(rte["rtep_vlan"].(int))
795-
796-
return &model.TransportNodeRemoteTunnelEndpointConfig{
797-
HostSwitchName: &hostSwitchName,
798-
IpAssignmentSpec: ipAssignment,
799-
NamedTeamingPolicy: &namedTeamingPolicy,
800-
RtepVlan: &rtepVlan,
801-
}, nil
802-
}
803-
return nil, nil
804-
}
805-
806753
func getEdgeNodeDeploymentConfigFromSchema(cfg interface{}) (*model.EdgeNodeDeploymentConfig, error) {
807754
converter := bindings.NewTypeConverter()
808755

@@ -1139,7 +1086,7 @@ func getHostSwitchSpecFromSchema(d *schema.ResourceData, nodeType string) (*data
11391086
}
11401087
var transportNodeSubProfileCfg []model.TransportNodeProfileSubConfig
11411088
if nodeType == nodeTypeHost {
1142-
transportNodeSubProfileCfg = getTransportNodeSubProfileCfg(swData["transport_node_profile_sub_configs"])
1089+
transportNodeSubProfileCfg = getTransportNodeSubProfileCfg(swData["transport_node_profile_sub_config"])
11431090
}
11441091
transportZoneEndpoints := getTransportZoneEndpointsFromSchema(swData["transport_zone_endpoint"].([]interface{}))
11451092

@@ -1312,18 +1259,6 @@ func resourceNsxtEdgeTransportNodeRead(d *schema.ResourceData, m interface{}) er
13121259
return handleReadError(d, "TransportNode", id, err)
13131260
}
13141261

1315-
if obj.RemoteTunnelEndpoint != nil {
1316-
rtep := make(map[string]interface{})
1317-
rtep["host_switch_name"] = obj.RemoteTunnelEndpoint.HostSwitchName
1318-
rtep["ip_assignment"], err = setIPAssignmentInSchema(obj.RemoteTunnelEndpoint.IpAssignmentSpec)
1319-
if err != nil {
1320-
return handleReadError(d, "TransportNode", id, err)
1321-
}
1322-
rtep["named_teaming_policy"] = obj.RemoteTunnelEndpoint.NamedTeamingPolicy
1323-
rtep["rtep_vlan"] = obj.RemoteTunnelEndpoint.RtepVlan
1324-
d.Set("remote_tunnel_endpoint", []map[string]interface{}{rtep})
1325-
}
1326-
13271262
return nil
13281263
}
13291264

@@ -1492,7 +1427,6 @@ func setHostSwitchSpecInSchema(d *schema.ResourceData, spec *data.StructValue, n
14921427
var tnpSubConfig []map[string]interface{}
14931428
for _, tnpsc := range sw.TransportNodeProfileSubConfigs {
14941429
e := make(map[string]interface{})
1495-
var hsCfgOpts []map[string]interface{}
14961430
hsCfgOpt := make(map[string]interface{})
14971431
hsCfgOpt["host_switch_id"] = tnpsc.HostSwitchConfigOption.HostSwitchId
14981432
profiles := setHostSwitchProfileIDsInSchema(tnpsc.HostSwitchConfigOption.HostSwitchProfileIds)
@@ -1504,8 +1438,9 @@ func setHostSwitchSpecInSchema(d *schema.ResourceData, spec *data.StructValue, n
15041438
return err
15051439
}
15061440
hsCfgOpt["uplink"] = setUplinksFromSchema(tnpsc.HostSwitchConfigOption.Uplinks)
1507-
e["host_switch_config_option"] = hsCfgOpts
1441+
e["host_switch_config_option"] = []interface{}{hsCfgOpt}
15081442
e["name"] = tnpsc.Name
1443+
tnpSubConfig = append(tnpSubConfig, e)
15091444
}
15101445
elem["transport_node_profile_sub_config"] = tnpSubConfig
15111446

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
/* Copyright © 2024 Broadcom, Inc. All Rights Reserved.
2+
SPDX-License-Identifier: MPL-2.0 */
3+
4+
package nsxt
5+
6+
import (
7+
"fmt"
8+
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
11+
"github.com/vmware/vsphere-automation-sdk-go/lib/vapi/std/errors"
12+
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt-mp/nsx"
13+
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt-mp/nsx/model"
14+
)
15+
16+
func resourceNsxtEdgeTransportNodeRTEP() *schema.Resource {
17+
return &schema.Resource{
18+
Create: resourceNsxtEdgeTransportNodeRTEPCreate,
19+
Read: resourceNsxtEdgeTransportNodeRTEPRead,
20+
Update: resourceNsxtEdgeTransportNodeRTEPUpdate,
21+
Delete: resourceNsxtEdgeTransportNodeRTEPDelete,
22+
Importer: &schema.ResourceImporter{
23+
State: schema.ImportStatePassthrough,
24+
},
25+
Schema: map[string]*schema.Schema{
26+
"edge_id": {
27+
Type: schema.TypeString,
28+
Description: "Edge ID to associate with remote tunnel endpoint.",
29+
Required: true,
30+
ForceNew: true,
31+
},
32+
"host_switch_name": {
33+
Type: schema.TypeString,
34+
Description: "The host switch name to be used for the remote tunnel endpoint",
35+
Required: true,
36+
},
37+
"ip_assignment": getIPAssignmentSchema(true),
38+
"named_teaming_policy": {
39+
Type: schema.TypeString,
40+
Description: "The named teaming policy to be used by the remote tunnel endpoint",
41+
Optional: true,
42+
},
43+
"rtep_vlan": {
44+
Type: schema.TypeInt,
45+
Description: "VLAN id for remote tunnel endpoint",
46+
Required: true,
47+
ValidateFunc: validation.IntBetween(0, 4094),
48+
},
49+
},
50+
}
51+
}
52+
53+
func resourceNsxtEdgeTransportNodeRTEPCreate(d *schema.ResourceData, m interface{}) error {
54+
connector := getPolicyConnector(m)
55+
client := nsx.NewTransportNodesClient(connector)
56+
57+
id := d.Get("edge_id").(string)
58+
59+
obj, err := client.Get(id)
60+
if err != nil {
61+
return handleCreateError("TransportNodeRTEP", id, err)
62+
}
63+
64+
if obj.RemoteTunnelEndpoint != nil {
65+
return fmt.Errorf("remote tunnel endpoint for Edge appliance %s already exists", id)
66+
}
67+
hostSwitchName := d.Get("host_switch_name").(string)
68+
namedTeamingPolicy := d.Get("named_teaming_policy").(string)
69+
rtepVlan := int64(d.Get("rtep_vlan").(int))
70+
71+
ipAssignment, err := getIPAssignmentFromSchema(d.Get("ip_assignment").([]interface{}))
72+
if err != nil {
73+
return err
74+
}
75+
76+
rtep := model.TransportNodeRemoteTunnelEndpointConfig{
77+
HostSwitchName: &hostSwitchName,
78+
IpAssignmentSpec: ipAssignment,
79+
NamedTeamingPolicy: &namedTeamingPolicy,
80+
RtepVlan: &rtepVlan,
81+
}
82+
obj.RemoteTunnelEndpoint = &rtep
83+
_, err = client.Update(id, obj, nil, nil, nil, nil, nil, nil, nil)
84+
if err != nil {
85+
return handleCreateError("TransportNodeRTEP", id, err)
86+
}
87+
88+
d.SetId(id)
89+
90+
return resourceNsxtEdgeTransportNodeRTEPRead(d, m)
91+
}
92+
93+
func resourceNsxtEdgeTransportNodeRTEPRead(d *schema.ResourceData, m interface{}) error {
94+
connector := getPolicyConnector(m)
95+
client := nsx.NewTransportNodesClient(connector)
96+
97+
id := d.Get("edge_id").(string)
98+
99+
obj, err := client.Get(id)
100+
if err != nil {
101+
return err
102+
}
103+
104+
if obj.RemoteTunnelEndpoint == nil {
105+
return errors.NotFound{}
106+
}
107+
108+
d.Set("host_switch_name", obj.RemoteTunnelEndpoint.HostSwitchName)
109+
ipAssignment, err := setIPAssignmentInSchema(obj.RemoteTunnelEndpoint.IpAssignmentSpec)
110+
if err != nil {
111+
return handleReadError(d, "TransportNodeRTEP", id, err)
112+
}
113+
d.Set("ip_assignment", ipAssignment)
114+
d.Set("named_teaming_policy", obj.RemoteTunnelEndpoint.NamedTeamingPolicy)
115+
d.Set("rtep_vlan", obj.RemoteTunnelEndpoint.RtepVlan)
116+
117+
return nil
118+
}
119+
120+
func resourceNsxtEdgeTransportNodeRTEPUpdate(d *schema.ResourceData, m interface{}) error {
121+
connector := getPolicyConnector(m)
122+
client := nsx.NewTransportNodesClient(connector)
123+
124+
id := d.Get("edge_id").(string)
125+
126+
obj, err := client.Get(id)
127+
if err != nil {
128+
return err
129+
}
130+
131+
if obj.RemoteTunnelEndpoint == nil {
132+
return errors.NotFound{}
133+
}
134+
135+
hostSwitchName := d.Get("host_switch_name").(string)
136+
namedTeamingPolicy := d.Get("named_teaming_policy").(string)
137+
rtepVlan := int64(d.Get("rtep_vlan").(int))
138+
139+
ipAssignment, err := getIPAssignmentFromSchema(d.Get("ip_assignment").([]interface{}))
140+
if err != nil {
141+
return err
142+
}
143+
144+
rtep := model.TransportNodeRemoteTunnelEndpointConfig{
145+
HostSwitchName: &hostSwitchName,
146+
IpAssignmentSpec: ipAssignment,
147+
NamedTeamingPolicy: &namedTeamingPolicy,
148+
RtepVlan: &rtepVlan,
149+
}
150+
obj.RemoteTunnelEndpoint = &rtep
151+
_, err = client.Update(id, obj, nil, nil, nil, nil, nil, nil, nil)
152+
if err != nil {
153+
return handleUpdateError("TransportNodeRTEP", id, err)
154+
}
155+
156+
return resourceNsxtEdgeTransportNodeRTEPRead(d, m)
157+
}
158+
159+
func resourceNsxtEdgeTransportNodeRTEPDelete(d *schema.ResourceData, m interface{}) error {
160+
connector := getPolicyConnector(m)
161+
client := nsx.NewTransportNodesClient(connector)
162+
163+
id := d.Get("edge_id").(string)
164+
165+
obj, err := client.Get(id)
166+
if err != nil {
167+
return err
168+
}
169+
170+
obj.RemoteTunnelEndpoint = nil
171+
172+
_, err = client.Update(id, obj, nil, nil, nil, nil, nil, nil, nil)
173+
if err != nil {
174+
return handleDeleteError("TransportNodeRTEP", id, err)
175+
}
176+
177+
return nil
178+
}

website/docs/r/edge_transport_node.html.markdown

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,6 @@ The following arguments are supported:
126126
* `port` - (Optional) Syslog server port. Defaults to 514.
127127
* `protocol` - (Optional) Syslog protocol. Accepted values - 'TCP', 'UDP', 'TLS', 'LI', 'LI_TLS'. The default value is 'UDP'.
128128
* `server` - (Required) Server IP or fqdn.
129-
* `remote_tunnel_endpoint` - (Optional) Configuration for a remote tunnel endpoint.
130-
* `host_switch_name` - (Required) The host switch name to be used for the remote tunnel endpoint.
131-
* `ip_assignment` - (Required) - Specification for IPs to be used with host switch virtual tunnel endpoints. Should contain exatly one of the below:
132-
* `assigned_by_dhcp` - (Optional) Enables DHCP assignment.
133-
* `static_ip` - (Optional) IP assignment specification for Static IP List.
134-
* `ip_addresses` - (Required) List of IPs for transport node host switch virtual tunnel endpoints.
135-
* `subnet_mask` - (Required) Subnet mask.
136-
* `default_gateway` - (Required) Gateway IP.
137-
* `static_ip_pool` - (Optional) IP assignment specification for Static IP Pool.
138-
* `named_teaming_policy` - (Optional) The named teaming policy to be used by the remote tunnel endpoint.
139-
* `rtep_vlan` - (Required) VLAN id for remote tunnel endpoint.
140129

141130
## Attributes Reference
142131

0 commit comments

Comments
 (0)