@@ -337,6 +337,13 @@ func resourceNsxtPolicyEdgeTransportNode() *schema.Resource {
337
337
ForceNew : true ,
338
338
Default : "default" ,
339
339
},
340
+ "node_id" : {
341
+ Type : schema .TypeString ,
342
+ Optional : true ,
343
+ Computed : true ,
344
+ Description : "Unique Id of the fabric node" ,
345
+ ConflictsWith : []string {"advanced_configuration" , "appliance_config" , "credentials" , "form_factor" , "management_interface" , "vm_deployment_config" },
346
+ },
340
347
"advanced_configuration" : getKeyValuePairListSchema (),
341
348
"appliance_config" : {
342
349
Type : schema .TypeList ,
@@ -1180,6 +1187,42 @@ func getVMDeploymentConfigFromSchema(iVmDeploymentCfg interface{}) (*data.Struct
1180
1187
return nil , nil
1181
1188
}
1182
1189
1190
+ func policyEdgeTransportNodePredeployedPatch (siteID , epID , etnID string , d * schema.ResourceData , m interface {}) error {
1191
+
1192
+ connector := getPolicyConnector (m )
1193
+ etnClient := enforcement_points .NewEdgeTransportNodesClient (connector )
1194
+
1195
+ obj , err := etnClient .Get (siteID , epID , etnID )
1196
+ if err != nil {
1197
+ return err
1198
+ }
1199
+
1200
+ description := d .Get ("description" ).(string )
1201
+ obj .Description = & description
1202
+
1203
+ displayName := d .Get ("display_name" ).(string )
1204
+ obj .DisplayName = & displayName
1205
+
1206
+ obj .Tags = getPolicyTagsFromSchema (d )
1207
+
1208
+ revision := int64 (d .Get ("revision" ).(int ))
1209
+ obj .Revision = & revision
1210
+
1211
+ failureDomainPath := d .Get ("failure_domain_path" ).(string )
1212
+ obj .FailureDomainPath = & failureDomainPath
1213
+
1214
+ hostname := d .Get ("hostname" ).(string )
1215
+ obj .Hostname = & hostname
1216
+
1217
+ switchSpec , err := getSwitchFromSchema (d .Get ("switch" ))
1218
+ if err != nil {
1219
+ return err
1220
+ }
1221
+ obj .SwitchSpec = switchSpec
1222
+
1223
+ return etnClient .Patch (siteID , epID , etnID , obj )
1224
+ }
1225
+
1183
1226
func policyEdgeTransportNodePatch (siteID , epID , etnID string , d * schema.ResourceData , m interface {}) error {
1184
1227
1185
1228
description := d .Get ("description" ).(string )
@@ -1230,9 +1273,15 @@ func policyEdgeTransportNodePatch(siteID, epID, etnID string, d *schema.Resource
1230
1273
1231
1274
func resourceNsxtPolicyEdgeTransportNodeCreate (d * schema.ResourceData , m interface {}) error {
1232
1275
connector := getPolicyConnector (m )
1276
+
1233
1277
id := d .Get ("nsx_id" ).(string )
1278
+ nodeID := d .Get ("node_id" ).(string )
1234
1279
if id == "" {
1235
- id = newUUID ()
1280
+ if nodeID != "" {
1281
+ id = nodeID
1282
+ } else {
1283
+ id = newUUID ()
1284
+ }
1236
1285
}
1237
1286
sitePath := d .Get ("site_path" ).(string )
1238
1287
siteID := getResourceIDFromResourcePath (sitePath , "sites" )
@@ -1243,19 +1292,31 @@ func resourceNsxtPolicyEdgeTransportNodeCreate(d *schema.ResourceData, m interfa
1243
1292
if epID == "" {
1244
1293
epID = getPolicyEnforcementPoint (m )
1245
1294
}
1246
- exists , err := resourceNsxtPolicyEdgeTransportNodeExists (siteID , epID , id , connector )
1247
- if err != nil {
1248
- return err
1249
- }
1250
- if exists {
1251
- return fmt .Errorf ("resource with ID %s already exists" , id )
1252
- }
1253
1295
1254
- // Create the resource using PATCH
1255
- log .Printf ("[INFO] Creating PolicyEdgeTransportNode with ID %s under site %s enforcement point %s" , id , siteID , epID )
1256
- err = policyEdgeTransportNodePatch (siteID , epID , id , d , m )
1257
- if err != nil {
1258
- return handleCreateError ("EdgeTransportNode" , id , err )
1296
+ if nodeID == "" {
1297
+ exists , err := resourceNsxtPolicyEdgeTransportNodeExists (siteID , epID , id , connector )
1298
+ if err != nil {
1299
+ return err
1300
+ }
1301
+ if exists {
1302
+ return fmt .Errorf ("resource with ID %s already exists" , id )
1303
+ }
1304
+
1305
+ // Create the resource using PATCH
1306
+ log .Printf ("[INFO] Creating PolicyEdgeTransportNode with ID %s under site %s enforcement point %s" , id , siteID , epID )
1307
+ err = policyEdgeTransportNodePatch (siteID , epID , id , d , m )
1308
+ if err != nil {
1309
+ return handleCreateError ("EdgeTransportNode" , id , err )
1310
+ }
1311
+ } else {
1312
+ log .Printf ("Adding a pre-existing Edge appliance" )
1313
+ if id != nodeID {
1314
+ return fmt .Errorf ("cannot have both nsx_id and node_id attribute set, with different values" )
1315
+ }
1316
+ err := policyEdgeTransportNodePredeployedPatch (siteID , epID , nodeID , d , m )
1317
+ if err != nil {
1318
+ return err
1319
+ }
1259
1320
}
1260
1321
1261
1322
d .SetId (id )
0 commit comments