@@ -337,6 +337,13 @@ func resourceNsxtPolicyEdgeTransportNode() *schema.Resource {
337337 ForceNew : true ,
338338 Default : "default" ,
339339 },
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+ },
340347 "advanced_configuration" : getKeyValuePairListSchema (),
341348 "appliance_config" : {
342349 Type : schema .TypeList ,
@@ -1180,6 +1187,42 @@ func getVMDeploymentConfigFromSchema(iVmDeploymentCfg interface{}) (*data.Struct
11801187 return nil , nil
11811188}
11821189
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+
11831226func policyEdgeTransportNodePatch (siteID , epID , etnID string , d * schema.ResourceData , m interface {}) error {
11841227
11851228 description := d .Get ("description" ).(string )
@@ -1230,9 +1273,15 @@ func policyEdgeTransportNodePatch(siteID, epID, etnID string, d *schema.Resource
12301273
12311274func resourceNsxtPolicyEdgeTransportNodeCreate (d * schema.ResourceData , m interface {}) error {
12321275 connector := getPolicyConnector (m )
1276+
12331277 id := d .Get ("nsx_id" ).(string )
1278+ nodeID := d .Get ("node_id" ).(string )
12341279 if id == "" {
1235- id = newUUID ()
1280+ if nodeID != "" {
1281+ id = nodeID
1282+ } else {
1283+ id = newUUID ()
1284+ }
12361285 }
12371286 sitePath := d .Get ("site_path" ).(string )
12381287 siteID := getResourceIDFromResourcePath (sitePath , "sites" )
@@ -1243,19 +1292,31 @@ func resourceNsxtPolicyEdgeTransportNodeCreate(d *schema.ResourceData, m interfa
12431292 if epID == "" {
12441293 epID = getPolicyEnforcementPoint (m )
12451294 }
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- }
12531295
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+ }
12591320 }
12601321
12611322 d .SetId (id )
0 commit comments