diff --git a/nsxt/data_source_nsxt_policy_host_transport_node.go b/nsxt/data_source_nsxt_policy_host_transport_node.go new file mode 100644 index 000000000..6aad09a2b --- /dev/null +++ b/nsxt/data_source_nsxt_policy_host_transport_node.go @@ -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 +} diff --git a/nsxt/data_source_nsxt_policy_host_transport_node_test.go b/nsxt/data_source_nsxt_policy_host_transport_node_test.go new file mode 100644 index 000000000..873cd97bb --- /dev/null +++ b/nsxt/data_source_nsxt_policy_host_transport_node_test.go @@ -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) +} diff --git a/nsxt/provider.go b/nsxt/provider.go index b36133563..d740a2050 100644 --- a/nsxt/provider.go +++ b/nsxt/provider.go @@ -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{ diff --git a/nsxt/utils_test.go b/nsxt/utils_test.go index 71927454c..e733bd39b 100644 --- a/nsxt/utils_test.go +++ b/nsxt/utils_test.go @@ -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 == "" { diff --git a/website/docs/d/policy_host_tranport_node.html.markdown b/website/docs/d/policy_host_tranport_node.html.markdown new file mode 100644 index 000000000..eabb27536 --- /dev/null +++ b/website/docs/d/policy_host_tranport_node.html.markdown @@ -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.