/
resource_acos_cloud_integration.go
339 lines (319 loc) · 12.6 KB
/
resource_acos_cloud_integration.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
package thunder
import (
"context"
edpt "github.com/a10networks/terraform-provider-thunder/thunder/axapi/endpoint"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func resourceAcosCloudIntegration() *schema.Resource {
return &schema.Resource{
Description: "`thunder_acos_cloud_integration`: Setting for heterogeneous cloud environment integration\n\n__PLACEHOLDER__",
CreateContext: resourceAcosCloudIntegrationCreate,
UpdateContext: resourceAcosCloudIntegrationUpdate,
ReadContext: resourceAcosCloudIntegrationRead,
DeleteContext: resourceAcosCloudIntegrationDelete,
Schema: map[string]*schema.Schema{
"dummy": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "dummy to make intermediate obj to single",
},
"ecosystem": {
Type: schema.TypeList, MaxItems: 1, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"dummy": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "dummy to make intermediate obj to single",
},
"uuid": {
Type: schema.TypeString, Optional: true, Computed: true, Description: "uuid of the object",
},
"consul": {
Type: schema.TypeList, MaxItems: 1, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"service_label": {
Type: schema.TypeList, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"service_label_name": {
Type: schema.TypeString, Optional: true, Description: "Name service group to be monitored",
},
},
},
},
"ipv4_address": {
Type: schema.TypeString, Optional: true, Description: "Configure the bootstrap server's IPv4 address (the host IPv4 address)",
},
"ipv6_address": {
Type: schema.TypeString, Optional: true, Description: "Configure the bootstrap server's IPv6 address (the host IPv6 address)",
},
"host_name": {
Type: schema.TypeString, Optional: true, Description: "Configure the host name for bootstrap server(e.g www.a10networks.com)",
},
"port": {
Type: schema.TypeInt, Optional: true, Description: "Configure the http port to use (port 8500)",
},
"health_check_interval": {
Type: schema.TypeString, Optional: true, Description: "'5': 5 seconds; '10': 10 seconds; '15': 15 seconds; '20': 20 seconds;",
},
"action": {
Type: schema.TypeString, Optional: true, Default: "disable", Description: "'enable': Enable Configuration; 'disable': Disable Configuration;",
},
"uuid": {
Type: schema.TypeString, Optional: true, Computed: true, Description: "uuid of the object",
},
},
},
},
"oracle": {
Type: schema.TypeList, MaxItems: 1, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"service_label": {
Type: schema.TypeList, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"service_label_name": {
Type: schema.TypeString, Optional: true, Description: "Name service group to be monitored",
},
},
},
},
"ipv4_address": {
Type: schema.TypeString, Optional: true, Description: "Configure the bootstrap server's IPv4 address (the host IPv4 address)",
},
"ipv6_address": {
Type: schema.TypeString, Optional: true, Description: "Configure the bootstrap server's IPv6 address (the host IPv6 address)",
},
"host_name": {
Type: schema.TypeString, Optional: true, Description: "Configure the host name for bootstrap server(e.g www.a10networks.com)",
},
"port": {
Type: schema.TypeInt, Optional: true, Description: "Configure the http port to use (port 8500)",
},
"health_check_interval": {
Type: schema.TypeString, Optional: true, Description: "'5': 5 seconds; '10': 10 seconds; '15': 15 seconds; '20': 20 seconds;",
},
"compartment_id": {
Type: schema.TypeString, Optional: true, Description: "OCI compartment id",
},
"tenancy_id": {
Type: schema.TypeString, Optional: true, Description: "OCI tenancy id",
},
"user_id": {
Type: schema.TypeString, Optional: true, Description: "OCI user id",
},
"fingerprint": {
Type: schema.TypeString, Optional: true, Description: "",
},
"private_key_path": {
Type: schema.TypeString, Optional: true, Description: "",
},
"action": {
Type: schema.TypeString, Optional: true, Default: "disable", Description: "'enable': Enable Configuration; 'disable': Disable Configuration;",
},
"uuid": {
Type: schema.TypeString, Optional: true, Computed: true, Description: "uuid of the object",
},
},
},
},
"k8s": {
Type: schema.TypeList, MaxItems: 1, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"action": {
Type: schema.TypeString, Optional: true, Default: "disable", Description: "'enable': Enable Configuration; 'disable': Disable Configuration;",
},
"health_check_interval": {
Type: schema.TypeString, Optional: true, Description: "'5': 5 seconds; '10': 10 seconds; '15': 15 seconds; '20': 20 seconds;",
},
"cluster_config_file": {
Type: schema.TypeString, Optional: true, Description: "Enter cluster config file name",
},
"service_label": {
Type: schema.TypeList, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"service_label_name": {
Type: schema.TypeString, Optional: true, Description: "Name service group to be monitored",
},
},
},
},
"uuid": {
Type: schema.TypeString, Optional: true, Computed: true, Description: "uuid of the object",
},
},
},
},
},
},
},
"uuid": {
Type: schema.TypeString, Optional: true, Computed: true, Description: "uuid of the object",
},
},
}
}
func resourceAcosCloudIntegrationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceAcosCloudIntegrationCreate()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointAcosCloudIntegration(d)
d.SetId(obj.GetId())
err := obj.Post(client.Token, client.Host, logger)
if err != nil {
return diag.FromErr(err)
}
return resourceAcosCloudIntegrationRead(ctx, d, meta)
}
return diags
}
func resourceAcosCloudIntegrationUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceAcosCloudIntegrationUpdate()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointAcosCloudIntegration(d)
err := obj.Put(client.Token, client.Host, logger)
if err != nil {
return diag.FromErr(err)
}
return resourceAcosCloudIntegrationRead(ctx, d, meta)
}
return diags
}
func resourceAcosCloudIntegrationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceAcosCloudIntegrationDelete()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointAcosCloudIntegration(d)
err := obj.Delete(client.Token, client.Host, d.Id(), logger)
if err != nil {
return diag.FromErr(err)
}
}
return diags
}
func resourceAcosCloudIntegrationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceAcosCloudIntegrationRead()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointAcosCloudIntegration(d)
err := obj.Get(client.Token, client.Host, d.Id(), logger)
if err != nil {
return diag.FromErr(err)
}
}
return diags
}
func getObjectAcosCloudIntegrationEcosystem47(d []interface{}) edpt.AcosCloudIntegrationEcosystem47 {
count1 := len(d)
var ret edpt.AcosCloudIntegrationEcosystem47
if count1 > 0 {
in := d[0].(map[string]interface{})
ret.Dummy = in["dummy"].(int)
//omit uuid
ret.Consul = getObjectAcosCloudIntegrationEcosystemConsul48(in["consul"].([]interface{}))
ret.Oracle = getObjectAcosCloudIntegrationEcosystemOracle50(in["oracle"].([]interface{}))
ret.K8s = getObjectAcosCloudIntegrationEcosystemK8s52(in["k8s"].([]interface{}))
}
return ret
}
func getObjectAcosCloudIntegrationEcosystemConsul48(d []interface{}) edpt.AcosCloudIntegrationEcosystemConsul48 {
count1 := len(d)
var ret edpt.AcosCloudIntegrationEcosystemConsul48
if count1 > 0 {
in := d[0].(map[string]interface{})
ret.ServiceLabel = getSliceAcosCloudIntegrationEcosystemConsulServiceLabel49(in["service_label"].([]interface{}))
ret.Ipv4Address = in["ipv4_address"].(string)
ret.Ipv6Address = in["ipv6_address"].(string)
ret.HostName = in["host_name"].(string)
ret.Port = in["port"].(int)
ret.HealthCheckInterval = in["health_check_interval"].(string)
ret.Action = in["action"].(string)
//omit uuid
}
return ret
}
func getSliceAcosCloudIntegrationEcosystemConsulServiceLabel49(d []interface{}) []edpt.AcosCloudIntegrationEcosystemConsulServiceLabel49 {
count1 := len(d)
ret := make([]edpt.AcosCloudIntegrationEcosystemConsulServiceLabel49, 0, count1)
for _, item := range d {
in := item.(map[string]interface{})
var oi edpt.AcosCloudIntegrationEcosystemConsulServiceLabel49
oi.ServiceLabelName = in["service_label_name"].(string)
ret = append(ret, oi)
}
return ret
}
func getObjectAcosCloudIntegrationEcosystemOracle50(d []interface{}) edpt.AcosCloudIntegrationEcosystemOracle50 {
count1 := len(d)
var ret edpt.AcosCloudIntegrationEcosystemOracle50
if count1 > 0 {
in := d[0].(map[string]interface{})
ret.ServiceLabel = getSliceAcosCloudIntegrationEcosystemOracleServiceLabel51(in["service_label"].([]interface{}))
ret.Ipv4Address = in["ipv4_address"].(string)
ret.Ipv6Address = in["ipv6_address"].(string)
ret.HostName = in["host_name"].(string)
ret.Port = in["port"].(int)
ret.HealthCheckInterval = in["health_check_interval"].(string)
ret.CompartmentId = in["compartment_id"].(string)
ret.TenancyId = in["tenancy_id"].(string)
ret.UserId = in["user_id"].(string)
ret.Fingerprint = in["fingerprint"].(string)
ret.PrivateKeyPath = in["private_key_path"].(string)
ret.Action = in["action"].(string)
//omit uuid
}
return ret
}
func getSliceAcosCloudIntegrationEcosystemOracleServiceLabel51(d []interface{}) []edpt.AcosCloudIntegrationEcosystemOracleServiceLabel51 {
count1 := len(d)
ret := make([]edpt.AcosCloudIntegrationEcosystemOracleServiceLabel51, 0, count1)
for _, item := range d {
in := item.(map[string]interface{})
var oi edpt.AcosCloudIntegrationEcosystemOracleServiceLabel51
oi.ServiceLabelName = in["service_label_name"].(string)
ret = append(ret, oi)
}
return ret
}
func getObjectAcosCloudIntegrationEcosystemK8s52(d []interface{}) edpt.AcosCloudIntegrationEcosystemK8s52 {
count1 := len(d)
var ret edpt.AcosCloudIntegrationEcosystemK8s52
if count1 > 0 {
in := d[0].(map[string]interface{})
ret.Action = in["action"].(string)
ret.HealthCheckInterval = in["health_check_interval"].(string)
ret.ClusterConfigFile = in["cluster_config_file"].(string)
ret.ServiceLabel = getSliceAcosCloudIntegrationEcosystemK8sServiceLabel53(in["service_label"].([]interface{}))
//omit uuid
}
return ret
}
func getSliceAcosCloudIntegrationEcosystemK8sServiceLabel53(d []interface{}) []edpt.AcosCloudIntegrationEcosystemK8sServiceLabel53 {
count1 := len(d)
ret := make([]edpt.AcosCloudIntegrationEcosystemK8sServiceLabel53, 0, count1)
for _, item := range d {
in := item.(map[string]interface{})
var oi edpt.AcosCloudIntegrationEcosystemK8sServiceLabel53
oi.ServiceLabelName = in["service_label_name"].(string)
ret = append(ret, oi)
}
return ret
}
func dataToEndpointAcosCloudIntegration(d *schema.ResourceData) edpt.AcosCloudIntegration {
var ret edpt.AcosCloudIntegration
ret.Inst.Dummy = d.Get("dummy").(int)
ret.Inst.Ecosystem = getObjectAcosCloudIntegrationEcosystem47(d.Get("ecosystem").([]interface{}))
//omit uuid
return ret
}