Skip to content

Commit 29d383f

Browse files
authored
Merge pull request #1019 from ksamoray/ds-host-xport-node
Implement policy_host_transport_node data source
2 parents 3536d97 + 3a8a9e3 commit 29d383f

5 files changed

+123
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* Copyright © 2023 VMware, Inc. All Rights Reserved.
2+
SPDX-License-Identifier: MPL-2.0 */
3+
4+
package nsxt
5+
6+
import (
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
8+
"github.com/vmware/vsphere-automation-sdk-go/runtime/bindings"
9+
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model"
10+
)
11+
12+
func dataSourceNsxtPolicyHostTransportNode() *schema.Resource {
13+
return &schema.Resource{
14+
Read: dataSourceNsxtPolicyHostTransportNodeRead,
15+
16+
Schema: map[string]*schema.Schema{
17+
"id": getDataSourceIDSchema(),
18+
"display_name": getDataSourceDisplayNameSchema(),
19+
"description": getDataSourceDescriptionSchema(),
20+
"path": getPathSchema(),
21+
"unique_id": {
22+
Type: schema.TypeString,
23+
Computed: true,
24+
Description: "A unique identifier assigned by the system",
25+
},
26+
},
27+
}
28+
}
29+
30+
func dataSourceNsxtPolicyHostTransportNodeRead(d *schema.ResourceData, m interface{}) error {
31+
obj, err := policyDataSourceResourceRead(d, getPolicyConnector(m), getSessionContext(d, m), "HostTransportNode", nil)
32+
if err != nil {
33+
return err
34+
}
35+
converter := bindings.NewTypeConverter()
36+
dataValue, errors := converter.ConvertToGolang(obj, model.HostTransportNodeBindingType())
37+
if len(errors) > 0 {
38+
return errors[0]
39+
}
40+
htn := dataValue.(model.HostTransportNode)
41+
d.Set("unique_id", htn.UniqueId)
42+
43+
return nil
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* Copyright © 2023 VMware, Inc. All Rights Reserved.
2+
SPDX-License-Identifier: MPL-2.0 */
3+
4+
package nsxt
5+
6+
import (
7+
"fmt"
8+
"testing"
9+
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
11+
)
12+
13+
func TestAccDataSourceNsxtPolicyHostTransportNode_basic(t *testing.T) {
14+
htnName := getHostTransportNodeName()
15+
testResourceName := "data.nsxt_policy_host_transport_node.test"
16+
17+
resource.ParallelTest(t, resource.TestCase{
18+
PreCheck: func() {
19+
testAccOnlyLocalManager(t)
20+
testAccPreCheck(t)
21+
testAccEnvDefined(t, "NSXT_TEST_HOST_TRANSPORT_NODE")
22+
},
23+
Providers: testAccProviders,
24+
Steps: []resource.TestStep{
25+
{
26+
Config: testAccNSXHostTransportNodeReadTemplate(htnName),
27+
Check: resource.ComposeTestCheckFunc(
28+
resource.TestCheckResourceAttr(testResourceName, "display_name", htnName),
29+
resource.TestCheckResourceAttrSet(testResourceName, "id"),
30+
resource.TestCheckResourceAttrSet(testResourceName, "unique_id"),
31+
),
32+
},
33+
},
34+
})
35+
}
36+
37+
func testAccNSXHostTransportNodeReadTemplate(name string) string {
38+
return fmt.Sprintf(`
39+
data "nsxt_policy_host_transport_node" "test" {
40+
display_name = "%s"
41+
}`, name)
42+
}

nsxt/provider.go

+1
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ func Provider() *schema.Provider {
291291
"nsxt_failure_domain": dataSourceNsxtFailureDomain(),
292292
"nsxt_compute_collection": dataSourceNsxtComputeCollection(),
293293
"nsxt_compute_manager_realization": dataSourceNsxtComputeManagerRealization(),
294+
"nsxt_policy_host_transport_node": dataSourceNsxtPolicyHostTransportNode(),
294295
},
295296

296297
ResourcesMap: map[string]*schema.Resource{

nsxt/utils_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ func getComputeManagerName() string {
127127
return os.Getenv("NSXT_TEST_COMPUTE_MANAGER")
128128
}
129129

130+
func getHostTransportNodeName() string {
131+
return os.Getenv("NSXT_TEST_HOST_TRANSPORT_NODE")
132+
}
133+
130134
func getVlanTransportZoneName() string {
131135
name := os.Getenv("NSXT_TEST_VLAN_TRANSPORT_ZONE")
132136
if name == "" {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
subcategory: "Beta"
3+
layout: "nsxt"
4+
page_title: "NSXT: nsxt_policy_host_transport_node"
5+
description: A host transport node data source.
6+
---
7+
8+
# nsxt_policy_host_transport_node
9+
10+
This data source provides information about host transport node configured on NSX.
11+
This data source is applicable to NSX Policy Manager.
12+
13+
## Example Usage
14+
15+
```hcl
16+
data "nsxt_policy_host_transport_node" "host_transport_node" {
17+
display_name = "host_transport_node1"
18+
}
19+
```
20+
21+
## Argument Reference
22+
23+
* `id` - (Optional) The ID of host transport node to retrieve.
24+
* `display_name` - (Optional) The Display Name prefix of the host transport node to retrieve.
25+
26+
## Attributes Reference
27+
28+
In addition to arguments listed above, the following attributes are exported:
29+
30+
* `description` - The description of the resource.
31+
* `path` - The NSX path of the policy resource.
32+
* `unique_id` - A unique identifier assigned by the system.

0 commit comments

Comments
 (0)