forked from oracle/terraform-provider-oci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_source_obmcs_loadbalancer_loadbalancer_protocols.go
78 lines (65 loc) · 1.63 KB
/
data_source_obmcs_loadbalancer_loadbalancer_protocols.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
69
70
71
72
73
74
75
76
77
78
// Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
package main
import (
"time"
"github.com/hashicorp/terraform/helper/schema"
"github.com/oracle/bmcs-go-sdk"
"github.com/oracle/terraform-provider-oci/crud"
)
func ProtocolDatasource() *schema.Resource {
return &schema.Resource{
Read: readProtocols,
Schema: map[string]*schema.Schema{
"filter": dataSourceFiltersSchema(),
"compartment_id": {
Type: schema.TypeString,
Required: true,
},
"protocols": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
}
}
func readProtocols(d *schema.ResourceData, m interface{}) (e error) {
client := m.(*OracleClients)
sync := &ProtocolDatasourceCrud{}
sync.D = d
sync.Client = client.client
return crud.ReadResource(sync)
}
type ProtocolDatasourceCrud struct {
crud.BaseCrud
Res *baremetal.ListLoadBalancerProtocols
}
func (s *ProtocolDatasourceCrud) Get() (e error) {
cID := s.D.Get("compartment_id").(string)
s.Res, e = s.Client.ListLoadBalancerProtocols(cID, nil)
return
}
func (s *ProtocolDatasourceCrud) SetData() {
if s.Res != nil {
s.D.SetId(time.Now().UTC().String())
resources := []map[string]interface{}{}
for _, v := range s.Res.LoadBalancerProtocols {
res := map[string]interface{}{
"name": v.Name,
}
resources = append(resources, res)
}
if f, fOk := s.D.GetOk("filter"); fOk {
resources = ApplyFilters(f.(*schema.Set), resources)
}
s.D.Set("protocols", resources)
}
return
}