Skip to content

Add nsxt_policy_edge_transport_node data source #1601

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions nsxt/data_source_nsxt_policy_edge_transport_node.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// © Broadcom. All Rights Reserved.
// The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
// 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 dataSourceNsxtPolicyEdgeTransportNode() *schema.Resource {
return &schema.Resource{
Read: dataSourceNsxtPolicyEdgeTransportNodeRead,

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 dataSourceNsxtPolicyEdgeTransportNodeRead(d *schema.ResourceData, m interface{}) error {
obj, err := policyDataSourceResourceRead(d, getPolicyConnector(m), getSessionContext(d, m), "PolicyEdgeTransportNode", nil)
if err != nil {
return err
}
converter := bindings.NewTypeConverter()
dataValue, errors := converter.ConvertToGolang(obj, model.PolicyEdgeTransportNodeBindingType())
if len(errors) > 0 {
return errors[0]
}
etn := dataValue.(model.PolicyEdgeTransportNode)
d.Set("unique_id", etn.UniqueId)

return nil
}
44 changes: 44 additions & 0 deletions nsxt/data_source_nsxt_policy_edge_transport_node_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// © Broadcom. All Rights Reserved.
// The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
// SPDX-License-Identifier: MPL-2.0

package nsxt

import (
"fmt"
"testing"

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

func TestAccDataSourceNsxtPolicyEdgeTransportNode_basic(t *testing.T) {
etnName := getEdgeTransportNodeName()
testResourceName := "data.nsxt_policy_edge_transport_node.test"

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

func testAccNSXEdgeTransportNodeReadTemplate(name string) string {
return fmt.Sprintf(`
data "nsxt_policy_edge_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 @@ -344,6 +344,7 @@ func Provider() *schema.Provider {
"nsxt_policy_distributed_vlan_connection": dataSourceNsxtPolicyDistributedVlanConnection(),
"nsxt_policy_services": dataSourceNsxtPolicyServices(),
"nsxt_policy_groups": dataSourceNsxtPolicyGroups(),
"nsxt_policy_edge_transport_node": dataSourceNsxtPolicyEdgeTransportNode(),
},

ResourcesMap: map[string]*schema.Resource{
Expand Down
2 changes: 1 addition & 1 deletion website/docs/d/policy_edge_node.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description: A policy Edge Node data source.

# nsxt_policy_edge_node

This data source provides information about policy edge nodes configured on NSX.
This data source provides information about policy edge nodes configured within a cluster, on NSX.

This data source is applicable to NSX Global Manager and NSX Policy Manager.

Expand Down
32 changes: 32 additions & 0 deletions website/docs/d/policy_edge_transport_node.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
subcategory: "Fabric"
layout: "nsxt"
page_title: "NSXT: nsxt_policy_edge_transport_node"
description: An Edge transport node data source.
---

# nsxt_policy_edge_transport_node

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

## Example Usage

```hcl
data "nsxt_policy_edge_transport_node" "edge_transport_node" {
display_name = "edge_transport_node1"
}
```

## Argument Reference

* `id` - (Optional) The ID of Edge transport node to retrieve.
* `display_name` - (Optional) The Display Name prefix of the Edge 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.
Loading