|
| 1 | +/* Copyright © 2023 VMware, Inc. All Rights Reserved. |
| 2 | + SPDX-License-Identifier: MPL-2.0 */ |
| 3 | + |
| 4 | +package nsxt |
| 5 | + |
| 6 | +import ( |
| 7 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| 8 | + "github.com/vmware/vsphere-automation-sdk-go/runtime/bindings" |
| 9 | + "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model" |
| 10 | +) |
| 11 | + |
| 12 | +func dataSourceNsxtPolicyHostTransportNode() *schema.Resource { |
| 13 | + return &schema.Resource{ |
| 14 | + Read: dataSourceNsxtPolicyHostTransportNodeRead, |
| 15 | + |
| 16 | + Schema: map[string]*schema.Schema{ |
| 17 | + "id": getDataSourceIDSchema(), |
| 18 | + "display_name": getDataSourceDisplayNameSchema(), |
| 19 | + "description": getDataSourceDescriptionSchema(), |
| 20 | + "path": getPathSchema(), |
| 21 | + "unique_id": { |
| 22 | + Type: schema.TypeString, |
| 23 | + Computed: true, |
| 24 | + Description: "A unique identifier assigned by the system", |
| 25 | + }, |
| 26 | + }, |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +func dataSourceNsxtPolicyHostTransportNodeRead(d *schema.ResourceData, m interface{}) error { |
| 31 | + obj, err := policyDataSourceResourceRead(d, getPolicyConnector(m), getSessionContext(d, m), "HostTransportNode", nil) |
| 32 | + if err != nil { |
| 33 | + return err |
| 34 | + } |
| 35 | + converter := bindings.NewTypeConverter() |
| 36 | + dataValue, errors := converter.ConvertToGolang(obj, model.HostTransportNodeBindingType()) |
| 37 | + if len(errors) > 0 { |
| 38 | + return errors[0] |
| 39 | + } |
| 40 | + htn := dataValue.(model.HostTransportNode) |
| 41 | + d.Set("unique_id", htn.UniqueId) |
| 42 | + |
| 43 | + return nil |
| 44 | +} |
0 commit comments