forked from oracle/terraform-provider-oci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_source_obmcs_loadbalancer_backends.go
73 lines (64 loc) · 1.62 KB
/
data_source_obmcs_loadbalancer_backends.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
// 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 BackendDatasource() *schema.Resource {
return &schema.Resource{
Read: readBackends,
Schema: map[string]*schema.Schema{
"load_balancer_id": {
Type: schema.TypeString,
Required: true,
},
"backendset_name": {
Type: schema.TypeString,
Required: true,
},
"backends": {
Type: schema.TypeList,
Computed: true,
Elem: LoadBalancerBackendResource(),
},
},
}
}
func readBackends(d *schema.ResourceData, m interface{}) (e error) {
client := m.(*OracleClients)
sync := &BackendDatasourceCrud{}
sync.D = d
sync.Client = client.client
return crud.ReadResource(sync)
}
type BackendDatasourceCrud struct {
crud.BaseCrud
Res *baremetal.ListBackends
}
func (s *BackendDatasourceCrud) Get() (e error) {
lbID := s.D.Get("load_balancer_id").(string)
backendSetName := s.D.Get("backendset_name").(string)
s.Res, e = s.Client.ListBackends(lbID, backendSetName)
return
}
func (s *BackendDatasourceCrud) SetData() {
if s.Res != nil {
s.D.SetId(time.Now().UTC().String())
resources := []map[string]interface{}{}
for _, v := range s.Res.Backends {
res := map[string]interface{}{
"ip_address": v.IPAddress,
"port": v.Port,
"backup": v.Backup,
"drain": v.Drain,
"offline": v.Offline,
"weight": v.Weight,
}
resources = append(resources, res)
}
s.D.Set("backends", resources)
}
return
}