Skip to content

Commit

Permalink
Implement policy_host_transport_node data source
Browse files Browse the repository at this point in the history
Signed-off-by: Kobi Samoray <[email protected]>
  • Loading branch information
ksamoray committed Nov 2, 2023
1 parent 32bc1a1 commit 3a8a9e3
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 0 deletions.
44 changes: 44 additions & 0 deletions nsxt/data_source_nsxt_policy_host_transport_node.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* Copyright © 2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: MPL-2.0 */

package nsxt

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/vmware/vsphere-automation-sdk-go/runtime/bindings"
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model"
)

func dataSourceNsxtPolicyHostTransportNode() *schema.Resource {
return &schema.Resource{
Read: dataSourceNsxtPolicyHostTransportNodeRead,

Schema: map[string]*schema.Schema{
"id": getDataSourceIDSchema(),
"display_name": getDataSourceDisplayNameSchema(),
"description": getDataSourceDescriptionSchema(),
"path": getPathSchema(),
"unique_id": {
Type: schema.TypeString,
Computed: true,
Description: "A unique identifier assigned by the system",
},
},
}
}

func dataSourceNsxtPolicyHostTransportNodeRead(d *schema.ResourceData, m interface{}) error {
obj, err := policyDataSourceResourceRead(d, getPolicyConnector(m), getSessionContext(d, m), "HostTransportNode", nil)
if err != nil {
return err
}
converter := bindings.NewTypeConverter()
dataValue, errors := converter.ConvertToGolang(obj, model.HostTransportNodeBindingType())
if len(errors) > 0 {
return errors[0]
}
htn := dataValue.(model.HostTransportNode)
d.Set("unique_id", htn.UniqueId)

return nil
}
42 changes: 42 additions & 0 deletions nsxt/data_source_nsxt_policy_host_transport_node_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* Copyright © 2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: MPL-2.0 */

package nsxt

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccDataSourceNsxtPolicyHostTransportNode_basic(t *testing.T) {
htnName := getHostTransportNodeName()
testResourceName := "data.nsxt_policy_host_transport_node.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
testAccOnlyLocalManager(t)
testAccPreCheck(t)
testAccEnvDefined(t, "NSXT_TEST_HOST_TRANSPORT_NODE")
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccNSXHostTransportNodeReadTemplate(htnName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(testResourceName, "display_name", htnName),
resource.TestCheckResourceAttrSet(testResourceName, "id"),
resource.TestCheckResourceAttrSet(testResourceName, "unique_id"),
),
},
},
})
}

func testAccNSXHostTransportNodeReadTemplate(name string) string {
return fmt.Sprintf(`
data "nsxt_policy_host_transport_node" "test" {
display_name = "%s"
}`, name)
}
1 change: 1 addition & 0 deletions nsxt/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ func Provider() *schema.Provider {
"nsxt_failure_domain": dataSourceNsxtFailureDomain(),
"nsxt_compute_collection": dataSourceNsxtComputeCollection(),
"nsxt_compute_manager_realization": dataSourceNsxtComputeManagerRealization(),
"nsxt_policy_host_transport_node": dataSourceNsxtPolicyHostTransportNode(),
},

ResourcesMap: map[string]*schema.Resource{
Expand Down
4 changes: 4 additions & 0 deletions nsxt/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ func getComputeManagerName() string {
return os.Getenv("NSXT_TEST_COMPUTE_MANAGER")
}

func getHostTransportNodeName() string {
return os.Getenv("NSXT_TEST_HOST_TRANSPORT_NODE")
}

func getVlanTransportZoneName() string {
name := os.Getenv("NSXT_TEST_VLAN_TRANSPORT_ZONE")
if name == "" {
Expand Down
32 changes: 32 additions & 0 deletions website/docs/d/policy_host_tranport_node.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
subcategory: "Beta"
layout: "nsxt"
page_title: "NSXT: nsxt_policy_host_transport_node"
description: A host transport node data source.
---

# nsxt_policy_host_transport_node

This data source provides information about host transport node configured on NSX.
This data source is applicable to NSX Policy Manager.

## Example Usage

```hcl
data "nsxt_policy_host_transport_node" "host_transport_node" {
display_name = "host_transport_node1"
}
```

## Argument Reference

* `id` - (Optional) The ID of host transport node to retrieve.
* `display_name` - (Optional) The Display Name prefix of the host transport node to retrieve.

## Attributes Reference

In addition to arguments listed above, the following attributes are exported:

* `description` - The description of the resource.
* `path` - The NSX path of the policy resource.
* `unique_id` - A unique identifier assigned by the system.

0 comments on commit 3a8a9e3

Please sign in to comment.