-
Notifications
You must be signed in to change notification settings - Fork 134
/
data_source_tc_emr_nodes.go
513 lines (498 loc) · 16.2 KB
/
data_source_tc_emr_nodes.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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
package emr
import (
"context"
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
emr "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/emr/v20190103"
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
)
func DataSourceTencentCloudEmrNodes() *schema.Resource {
return &schema.Resource{
Read: dataSourceTencentCloudEmrNodesRead,
Schema: map[string]*schema.Schema{
"instance_id": {
Type: schema.TypeString,
Required: true,
Description: "Cluster instance ID, the instance ID is as follows: emr-xxxxxxxx.",
},
"node_flag": {
Type: schema.TypeString,
Required: true,
Description: `Node ID, the value is:
- all: Means to get all type nodes, except cdb information.
- master: Indicates that the master node information is obtained.
- core: Indicates that the core node information is obtained.
- task: indicates obtaining task node information.
- common: means to get common node information.
- router: Indicates obtaining router node information.
- db: Indicates that the cdb information for the normal state is obtained.
- recyle: Indicates that the node information in the Recycle Bin isolation, including the cdb information, is obtained.
- renew: Indicates that all node information to be renewed, including cddb information, is obtained, and the auto-renewal node will not be returned.
Note: Only the above values are now supported, entering other values will cause an error.`,
},
"hardware_resource_type": {
Type: schema.TypeString,
Optional: true,
Default: "all",
Description: "Resource type: Support all/host/pod, default is all.",
},
"offset": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
Description: "Page number, with a default value of 0, represents the first page.",
},
"limit": {
Type: schema.TypeInt,
Optional: true,
Default: 100,
Description: "The number returned per page, the default value is 100, and the maximum value is 100.",
},
"result_output_file": {
Type: schema.TypeString,
Optional: true,
Description: "Used to save results.",
},
"nodes": {
Type: schema.TypeList,
Computed: true,
Description: "List of node details.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"app_id": {
Type: schema.TypeInt,
Computed: true,
Description: "User APPID.",
},
"serial_no": {
Type: schema.TypeString,
Computed: true,
Description: "Serial number.",
},
"order_no": {
Type: schema.TypeString,
Computed: true,
Description: "Machine instance ID.",
},
"wan_ip": {
Type: schema.TypeString,
Computed: true,
Description: "The master node is bound to the Internet IP address.",
},
"flag": {
Type: schema.TypeInt,
Computed: true,
Description: "Node type. 0: common node; 1: master node; 2: core node; 3: task node.",
},
"spec": {
Type: schema.TypeString,
Computed: true,
Description: "Node specifications.",
},
"cpu_num": {
Type: schema.TypeInt,
Computed: true,
Description: "Number of node cores.",
},
"mem_size": {
Type: schema.TypeInt,
Computed: true,
Description: "Node memory.",
},
"mem_desc": {
Type: schema.TypeString,
Computed: true,
Description: "Node memory description.",
},
"region_id": {
Type: schema.TypeInt,
Computed: true,
Description: "The node is located in the region.",
},
"zone_id": {
Type: schema.TypeInt,
Computed: true,
Description: "Zone where the node is located.",
},
"apply_time": {
Type: schema.TypeString,
Computed: true,
Description: "Application time.",
},
"free_time": {
Type: schema.TypeString,
Computed: true,
Description: "Release time.",
},
"disk_size": {
Type: schema.TypeString,
Computed: true,
Description: "Hard disk size.",
},
"name_tag": {
Type: schema.TypeString,
Computed: true,
Description: "Node description.",
},
"services": {
Type: schema.TypeString,
Computed: true,
Description: "Node deployment service.",
},
"storage_type": {
Type: schema.TypeInt,
Computed: true,
Description: "Disk type.",
},
"root_size": {
Type: schema.TypeInt,
Computed: true,
Description: "The size of the system disk.",
},
"charge_type": {
Type: schema.TypeInt,
Computed: true,
Description: "The type of payment.",
},
"cdb_ip": {
Type: schema.TypeString,
Computed: true,
Description: "Database IP.",
},
"cdb_port": {
Type: schema.TypeInt,
Computed: true,
Description: "Database port.",
},
"hw_disk_size": {
Type: schema.TypeInt,
Computed: true,
Description: "Hard disk capacity.",
},
"hw_disk_size_desc": {
Type: schema.TypeString,
Computed: true,
Description: "Hard disk capacity description.",
},
"hw_mem_size": {
Type: schema.TypeInt,
Computed: true,
Description: "Memory capacity.",
},
"hw_mem_size_desc": {
Type: schema.TypeString,
Computed: true,
Description: "Memory capacity description.",
},
"expire_time": {
Type: schema.TypeString,
Computed: true,
Description: "Expiration time.",
},
"emr_resource_id": {
Type: schema.TypeString,
Computed: true,
Description: "Node resource ID.",
},
"is_auto_renew": {
Type: schema.TypeInt,
Computed: true,
Description: "Renewal logo.",
},
"device_class": {
Type: schema.TypeString,
Computed: true,
Description: "Device identity.",
},
"mutable": {
Type: schema.TypeInt,
Computed: true,
Description: "Supports variations.",
},
"ip": {
Type: schema.TypeString,
Computed: true,
Description: "Intranet IP.",
},
"destroyable": {
Type: schema.TypeInt,
Computed: true,
Description: "Whether this node is destroyable, 1 can be destroyed, 0 is not destroyable.",
},
"auto_flag": {
Type: schema.TypeInt,
Computed: true,
Description: "Whether it is an autoscaling node, 0 is a normal node, and 1 is an autoscaling node.",
},
"hardware_resource_type": {
Type: schema.TypeString,
Computed: true,
Description: "Resource type, host/pod.",
},
"is_dynamic_spec": {
Type: schema.TypeInt,
Computed: true,
Description: "Floating specifications, 1 yes, 0 no.",
},
"dynamic_pod_spec": {
Type: schema.TypeString,
Computed: true,
Description: "Floating specification value json string.",
},
"support_modify_pay_mode": {
Type: schema.TypeInt,
Computed: true,
Description: "Whether to support change billing type 1 Yes and 0 No.",
},
"cdb_node_info": {
Type: schema.TypeList,
Computed: true,
Description: "Database information.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"instance_name": {
Type: schema.TypeString,
Computed: true,
Description: "DB instance.",
},
"ip": {
Type: schema.TypeString,
Computed: true,
Description: "Database IP.",
},
"port": {
Type: schema.TypeInt,
Computed: true,
Description: "Database port.",
},
"mem_size": {
Type: schema.TypeInt,
Computed: true,
Description: "Database memory specifications.",
},
"volume": {
Type: schema.TypeInt,
Computed: true,
Description: "Database disk specifications.",
},
"service": {
Type: schema.TypeString,
Computed: true,
Description: "The service identity.",
},
"expire_time": {
Type: schema.TypeString,
Computed: true,
Description: "Expiration time.",
},
"apply_time": {
Type: schema.TypeString,
Computed: true,
Description: "Application time.",
},
"pay_type": {
Type: schema.TypeInt,
Computed: true,
Description: "The type of payment.",
},
"expire_flag": {
Type: schema.TypeBool,
Computed: true,
Description: "Expired id.",
},
"status": {
Type: schema.TypeInt,
Computed: true,
Description: "Database status.",
},
"is_auto_renew": {
Type: schema.TypeInt,
Computed: true,
Description: "Renewal identity.",
},
"serial_no": {
Type: schema.TypeString,
Computed: true,
Description: "Database string.",
},
"zone_id": {
Type: schema.TypeInt,
Computed: true,
Description: "Zone Id.",
},
"region_id": {
Type: schema.TypeInt,
Computed: true,
Description: "Region id.",
},
},
},
},
"mc_multi_disks": {
Type: schema.TypeList,
Computed: true,
Description: "Multi-cloud disk.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"count": {
Type: schema.TypeInt,
Computed: true,
Description: "The number of cloud disks of this type.",
},
"type": {
Type: schema.TypeInt,
Computed: true,
Description: "Disk type.",
},
"volume": {
Type: schema.TypeInt,
Computed: true,
Description: "The size of the cloud disk.",
},
},
},
},
"tags": {
Type: schema.TypeList,
Computed: true,
Description: "The label of the node binding.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"tag_key": {
Type: schema.TypeString,
Computed: true,
Description: "Tag key.",
},
"tag_value": {
Type: schema.TypeString,
Computed: true,
Description: "Tag value.",
},
},
},
},
},
},
},
},
}
}
func dataSourceTencentCloudEmrNodesRead(d *schema.ResourceData, meta interface{}) error {
defer tccommon.LogElapsed("data_source.tencentcloud_emr_nodes.read")()
logId := tccommon.GetLogId(tccommon.ContextNil)
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
instanceId := d.Get("instance_id").(string)
nodeFlag := d.Get("node_flag").(string)
offset := d.Get("offset").(int)
limit := d.Get("limit").(int)
hardwareResourceType := d.Get("hardware_resource_type").(string)
emrServer := EMRService{
client: meta.(tccommon.ProviderMeta).GetAPIV3Conn(),
}
var nodes []*emr.NodeHardwareInfo
err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
var errRet error
nodes, errRet = emrServer.DescribeClusterNodes(ctx, instanceId, nodeFlag, hardwareResourceType, offset, limit)
if errRet != nil {
return tccommon.RetryError(errRet, tccommon.InternalError)
}
return nil
})
if err != nil {
return err
}
emrNodes := make([]map[string]interface{}, 0)
ids := make([]string, 0)
for _, node := range nodes {
mcMultiDisks := node.MCMultiDisk
cdbNodeInfo := node.CdbNodeInfo
tags := node.Tags
mcMultiDiskList := make([]map[string]interface{}, 0)
cdbNodeInfoMap := make(map[string]interface{})
tagList := make([]map[string]interface{}, 0)
for _, mcMultiDisk := range mcMultiDisks {
tmpMCMultiDisk := make(map[string]interface{})
tmpMCMultiDisk["count"] = mcMultiDisk.Count
tmpMCMultiDisk["type"] = mcMultiDisk.Type
tmpMCMultiDisk["volume"] = mcMultiDisk.Volume
mcMultiDiskList = append(mcMultiDiskList, tmpMCMultiDisk)
}
for _, tag := range tags {
tmpTag := make(map[string]interface{})
tmpTag["tag_key"] = tag.TagKey
tmpTag["tag_value"] = tag.TagValue
tagList = append(tagList, tmpTag)
}
if cdbNodeInfo != nil {
cdbNodeInfoMap["instance_name"] = cdbNodeInfo.InstanceName
cdbNodeInfoMap["ip"] = cdbNodeInfo.Ip
cdbNodeInfoMap["port"] = cdbNodeInfo.Port
cdbNodeInfoMap["mem_size"] = cdbNodeInfo.MemSize
cdbNodeInfoMap["volume"] = cdbNodeInfo.Volume
cdbNodeInfoMap["service"] = cdbNodeInfo.Service
cdbNodeInfoMap["expire_time"] = cdbNodeInfo.ExpireTime
cdbNodeInfoMap["apply_time"] = cdbNodeInfo.ApplyTime
cdbNodeInfoMap["pay_type"] = cdbNodeInfo.PayType
cdbNodeInfoMap["expire_flag"] = cdbNodeInfo.ExpireFlag
cdbNodeInfoMap["status"] = cdbNodeInfo.Status
cdbNodeInfoMap["is_auto_renew"] = cdbNodeInfo.IsAutoRenew
cdbNodeInfoMap["serial_no"] = cdbNodeInfo.SerialNo
cdbNodeInfoMap["zone_id"] = cdbNodeInfo.ZoneId
cdbNodeInfoMap["region_id"] = cdbNodeInfo.RegionId
}
nodeMap := map[string]interface{}{
"app_id": node.AppId,
"serial_no": node.SerialNo,
"order_no": node.OrderNo,
"wan_ip": node.WanIp,
"flag": node.Flag,
"spec": node.Spec,
"cpu_num": node.CpuNum,
"mem_size": node.MemSize,
"mem_desc": node.MemDesc,
"region_id": node.RegionId,
"zone_id": node.ZoneId,
"apply_time": node.ApplyTime,
"free_time": node.FreeTime,
"disk_size": node.DiskSize,
"name_tag": node.NameTag,
"services": node.Services,
"storage_type": node.StorageType,
"root_size": node.RootSize,
"charge_type": node.ChargeType,
"cdb_ip": node.CdbIp,
"cdb_port": node.CdbPort,
"hw_disk_size": node.HwDiskSize,
"hw_disk_size_desc": node.HwDiskSizeDesc,
"hw_mem_size": node.HwMemSize,
"hw_mem_size_desc": node.HwMemSizeDesc,
"expire_time": node.ExpireTime,
"emr_resource_id": node.EmrResourceId,
"is_auto_renew": node.IsAutoRenew,
"device_class": node.DeviceClass,
"mutable": node.Mutable,
"ip": node.Ip,
"destroyable": node.Destroyable,
"auto_flag": node.AutoFlag,
"hardware_resource_type": node.HardwareResourceType,
"is_dynamic_spec": node.IsDynamicSpec,
"dynamic_pod_spec": node.DynamicPodSpec,
"support_modify_pay_mode": node.SupportModifyPayMode,
"cdb_node_info": []map[string]interface{}{cdbNodeInfoMap},
"mc_multi_disks": mcMultiDiskList,
"tags": tagList,
}
ids = append(ids, (string)(*node.AppId))
emrNodes = append(emrNodes, nodeMap)
}
d.SetId(helper.DataResourceIdsHash(ids))
_ = d.Set("nodes", emrNodes)
output, ok := d.GetOk("result_output_file")
if ok && output.(string) != "" {
if err := tccommon.WriteToFile(output.(string), emrNodes); err != nil {
return err
}
}
return nil
}