/
data_source_ibm_cis_origin_pools.go
188 lines (177 loc) · 5.06 KB
/
data_source_ibm_cis_origin_pools.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package ibm
import (
"log"
"time"
"github.com/IBM/go-sdk-core/v3/core"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
const (
cisOriginPools = "cis_origin_pools"
)
func dataSourceIBMCISOriginPools() *schema.Resource {
return &schema.Resource{
Read: dataSourceIBMCISGLBPoolsRead,
Importer: &schema.ResourceImporter{},
Timeouts: &schema.ResourceTimeout{
Read: schema.DefaultTimeout(10 * time.Minute),
},
Schema: map[string]*schema.Schema{
cisID: {
Type: schema.TypeString,
Required: true,
Description: "DNS Zone CRN",
},
cisOriginPools: {
Type: schema.TypeList,
Description: "Collection of GLB pools detail",
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Description: "GLB Pools id",
},
cisGLBPoolID: {
Type: schema.TypeString,
Computed: true,
Description: "GLB Pool id",
},
cisGLBPoolName: {
Type: schema.TypeString,
Description: "name",
Computed: true,
},
cisGLBPoolRegions: {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "List of regions",
},
cisGLBPoolDesc: {
Type: schema.TypeString,
Computed: true,
Description: "Description of the CIS Origin Pool",
},
cisGLBPoolEnabled: {
Type: schema.TypeBool,
Computed: true,
Description: "Boolean value set to true if cis origin pool needs to be enabled",
},
cisGLBPoolMinimumOrigins: {
Type: schema.TypeInt,
Computed: true,
Description: "Minimum number of Origins",
},
cisGLBPoolMonitor: {
Type: schema.TypeString,
Computed: true,
Description: "Monitor value",
},
cisGLBPoolNotificationEMail: {
Type: schema.TypeString,
Computed: true,
Description: "Email address configured to recieve the notifications",
},
cisGLBPoolOrigins: {
Type: schema.TypeList,
Computed: true,
Description: "Origins info",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
cisGLBPoolOriginsName: {
Type: schema.TypeString,
Computed: true,
},
cisGLBPoolOriginsAddress: {
Type: schema.TypeString,
Computed: true,
},
cisGLBPoolOriginsEnabled: {
Type: schema.TypeBool,
Computed: true,
},
cisGLBPoolOriginsWeight: {
Type: schema.TypeFloat,
Computed: true,
},
cisGLBPoolOriginsHealthy: {
Type: schema.TypeBool,
Computed: true,
},
cisGLBPoolOriginsDisabledAt: {
Type: schema.TypeString,
Computed: true,
},
cisGLBPoolOriginsFailureReason: {
Type: schema.TypeString,
Computed: true,
},
},
},
},
cisGLBPoolHealthy: {
Type: schema.TypeBool,
Computed: true,
Description: "Health status",
},
cisGLBPoolCreatedOn: {
Type: schema.TypeString,
Computed: true,
Description: "Creation date info",
},
cisGLBPoolModifiedOn: {
Type: schema.TypeString,
Computed: true,
Description: "Modified date info",
},
},
},
},
},
}
}
func dataSourceIBMCISGLBPoolsRead(d *schema.ResourceData, meta interface{}) error {
cisClient, err := meta.(ClientSession).CisGLBPoolClientSession()
if err != nil {
return err
}
crn := d.Get(cisID).(string)
cisClient.Crn = core.StringPtr(crn)
opt := cisClient.NewListAllLoadBalancerPoolsOptions()
result, resp, err := cisClient.ListAllLoadBalancerPools(opt)
if err != nil {
log.Printf("Error listing global load balancer pools detail: %s", resp)
return err
}
pools := make([]map[string]interface{}, 0)
for _, instance := range result.Result {
pool := map[string]interface{}{}
pool["id"] = convertCisToTfTwoVar(*instance.ID, crn)
pool[cisGLBPoolID] = *instance.ID
pool[cisGLBPoolName] = *instance.Name
pool[cisGLBPoolOrigins] = flattenOrigins(instance.Origins)
pool[cisGLBPoolRegions] = instance.CheckRegions
pool[cisGLBPoolDesc] = *instance.Description
pool[cisGLBPoolEnabled] = *instance.Enabled
pool[cisGLBPoolNotificationEMail] = *instance.NotificationEmail
pool[cisGLBPoolCreatedOn] = *instance.CreatedOn
pool[cisGLBPoolModifiedOn] = *instance.ModifiedOn
if instance.Monitor != nil {
pool[cisGLBPoolMonitor] = *instance.Monitor
}
if instance.Healthy != nil {
pool[cisGLBPoolHealthy] = *instance.Healthy
}
pools = append(pools, pool)
}
d.SetId(dataSourceIBMCISGLBPoolsID(d))
d.Set(cisID, crn)
d.Set(cisOriginPools, pools)
return nil
}
func dataSourceIBMCISGLBPoolsID(d *schema.ResourceData) string {
return time.Now().UTC().String()
}