Skip to content

Commit 4ae26c3

Browse files
committed
Implement policy_host_transport_node data source
Signed-off-by: Kobi Samoray <[email protected]>
1 parent 32bc1a1 commit 4ae26c3

5 files changed

+104
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* Copyright © 2023 VMware, Inc. All Rights Reserved.
2+
SPDX-License-Identifier: MPL-2.0 */
3+
4+
package nsxt
5+
6+
import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
7+
8+
func dataSourceNsxtPolicyHostTransportNode() *schema.Resource {
9+
return &schema.Resource{
10+
Read: dataSourceNsxtPolicyHostTransportNodeRead,
11+
12+
Schema: map[string]*schema.Schema{
13+
"id": getDataSourceIDSchema(),
14+
"display_name": getDataSourceDisplayNameSchema(),
15+
"description": getDataSourceDescriptionSchema(),
16+
"path": getPathSchema(),
17+
},
18+
}
19+
}
20+
21+
func dataSourceNsxtPolicyHostTransportNodeRead(d *schema.ResourceData, m interface{}) error {
22+
_, err := policyDataSourceResourceRead(d, getPolicyConnector(m), getSessionContext(d, m), "HostTransportNode", nil)
23+
if err != nil {
24+
return err
25+
}
26+
return nil
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
),
31+
},
32+
},
33+
})
34+
}
35+
36+
func testAccNSXHostTransportNodeReadTemplate(name string) string {
37+
return fmt.Sprintf(`
38+
data "nsxt_policy_host_transport_node" "test" {
39+
display_name = "%s"
40+
}`, name)
41+
}

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,31 @@
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.

0 commit comments

Comments
 (0)