forked from vmware/terraform-provider-nsxt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_source_nsxt_policy_gateway_locale_service.go
68 lines (57 loc) · 2.07 KB
/
data_source_nsxt_policy_gateway_locale_service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* Copyright © 2021 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: MPL-2.0 */
package nsxt
import (
"fmt"
"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 dataSourceNsxtPolicyGatewayLocaleService() *schema.Resource {
return &schema.Resource{
Read: dataSourceNsxtPolicyGatewayLocaleServiceRead,
Schema: map[string]*schema.Schema{
"gateway_path": getPolicyPathSchema(true, true, "Gateway path"),
"id": getDataSourceIDSchema(),
"display_name": getDataSourceDisplayNameSchema(),
"description": getDataSourceDescriptionSchema(),
"path": getPathSchema(),
"bgp_path": getComputedPolicyPathSchema("Path for BGP config"),
"edge_cluster_path": {
Type: schema.TypeString,
Description: "The path of the edge cluster connected to this Tier0 gateway",
Optional: true,
Computed: true,
},
"context": getContextSchema(false, false, false),
},
}
}
func dataSourceNsxtPolicyGatewayLocaleServiceRead(d *schema.ResourceData, m interface{}) error {
connector := getPolicyConnector(m)
gwPath := d.Get("gateway_path").(string)
query := make(map[string]string)
query["parent_path"] = gwPath
obj, err := policyDataSourceResourceReadWithValidation(d, connector, getSessionContext(d, m), "LocaleServices", query, false)
if err != nil {
return err
}
converter := bindings.NewTypeConverter()
dataValue, errors := converter.ConvertToGolang(obj, model.LocaleServicesBindingType())
if len(errors) > 0 {
return errors[0]
}
localeService := dataValue.(model.LocaleServices)
if localeService.EdgeClusterPath != nil {
d.Set("edge_cluster_path", localeService.EdgeClusterPath)
}
d.SetId(*localeService.Id)
d.Set("display_name", localeService.DisplayName)
d.Set("description", localeService.Description)
d.Set("path", localeService.Path)
if localeService.Path != nil {
bgpPath := fmt.Sprintf("%s/bgp", *localeService.Path)
d.Set("bgp_path", bgpPath)
}
return nil
}