-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Add Discover Node data source. 2. Remove node_deployment_info from Host Transport Node. Considering we only support Host Transport Node create from vCenter server managing the ESXi type HostNode and in this case, discovered_node_id is required, so no need to provide node_deployment_info. Additionally, this could fix the issue that using node_deployment_info with VDS type host switch, which is the only host switch type supported, will receive error from NSX: ``` Failed to create HostTransportNode 9756979d-0165-4cc6-93dc-0c30bb6da065: VDS Configuration is specified for host 9756979d-0165-4cc6-93dc-0c30bb6da065 and its not managed by a vCenter. Please correct TransportNode configuration or connect the host to a VCenter. (code 9549) ``` Signed-off-by: graysonwu <[email protected]>
- Loading branch information
Showing
5 changed files
with
110 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* Copyright © 2024 VMware, Inc. All Rights Reserved. | ||
SPDX-License-Identifier: MPL-2.0 */ | ||
|
||
package nsxt | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt-mp/nsx/fabric" | ||
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt-mp/nsx/model" | ||
) | ||
|
||
func dataSourceNsxtDiscoverNode() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceNsxtDiscoverNodeRead, | ||
Schema: map[string]*schema.Schema{ | ||
"id": { | ||
Type: schema.TypeString, | ||
Description: "External id of the discovered node, ex. a mo-ref from VC", | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
"ip_address": { | ||
Type: schema.TypeString, | ||
Description: "IP Address of the the discovered node.", | ||
Optional: true, | ||
Computed: true, | ||
ValidateFunc: validateCidrOrIPOrRange(), | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceNsxtDiscoverNodeRead(d *schema.ResourceData, m interface{}) error { | ||
connector := getPolicyConnector(m) | ||
discoverNodeClient := fabric.NewDiscoveredNodesClient(connector) | ||
|
||
objID := d.Get("id").(string) | ||
ipAddress := d.Get("ip_address").(string) | ||
|
||
var obj model.DiscoveredNode | ||
if objID != "" { | ||
// Get by ID | ||
objGet, err := discoverNodeClient.Get(objID) | ||
if isNotFoundError(err) { | ||
return fmt.Errorf("Discover Node %s was not found", objID) | ||
} | ||
if err != nil { | ||
return fmt.Errorf("Error while reading Discover Node %s: %v", objID, err) | ||
} | ||
obj = objGet | ||
} else if ipAddress == "" { | ||
return fmt.Errorf("Error obtaining Discover Node external ID or IP address during read") | ||
} else { | ||
// Get by IP address | ||
objList, err := discoverNodeClient.List(nil, nil, nil, nil, nil, nil, &ipAddress, nil, nil, nil, nil, nil, nil, nil) | ||
if isNotFoundError(err) { | ||
return fmt.Errorf("Discover Node with IP %s was not found", ipAddress) | ||
} | ||
if err != nil { | ||
return fmt.Errorf("Error while reading Discover Node: %v", err) | ||
} | ||
obj = objList.Results[0] | ||
} | ||
|
||
d.SetId(*obj.ExternalId) | ||
d.Set("ip_address", obj.IpAddresses[0]) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
subcategory: "Fabric" | ||
layout: "nsxt" | ||
page_title: "NSXT: discover_node" | ||
description: An Discover Node data source. | ||
--- | ||
|
||
# nsxt_discover_node | ||
|
||
This data source provides information about Discover Node configured in NSX. A Discover Node can be used to create a Host Transport Node. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "nsxt_discover_node" "test" { | ||
ip_address = "10.43.251.142" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `id` - (Optional) External id of the discovered node, ex. a mo-ref from VC. | ||
* `ip_address` - (Optional) IP Address of the discovered node. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters