-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement policy_host_transport_node data source
Signed-off-by: Kobi Samoray <[email protected]>
- Loading branch information
Showing
5 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |