6
6
"fmt"
7
7
8
8
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
9
+ "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
9
10
svccdb "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/cdb"
10
11
svctag "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/tag"
11
12
@@ -22,11 +23,14 @@ func ResourceTencentCloudEmrCluster() *schema.Resource {
22
23
Read : resourceTencentCloudEmrClusterRead ,
23
24
Delete : resourceTencentCloudEmrClusterDelete ,
24
25
Update : resourceTencentCloudEmrClusterUpdate ,
26
+ Importer : & schema.ResourceImporter {
27
+ State : schema .ImportStatePassthrough ,
28
+ },
25
29
Schema : map [string ]* schema.Schema {
26
30
"display_strategy" : {
27
31
Type : schema .TypeString ,
28
- Required : true ,
29
- ForceNew : true ,
32
+ Optional : true ,
33
+ Deprecated : "It will be deprecated in later versions." ,
30
34
Description : "Display strategy of EMR instance." ,
31
35
},
32
36
"product_id" : {
@@ -54,7 +58,7 @@ func ResourceTencentCloudEmrCluster() *schema.Resource {
54
58
Description : "The private net config of EMR instance." ,
55
59
},
56
60
"softwares" : {
57
- Type : schema .TypeList ,
61
+ Type : schema .TypeSet ,
58
62
Required : true ,
59
63
ForceNew : true ,
60
64
Elem : & schema.Schema {Type : schema .TypeString },
@@ -71,22 +75,26 @@ func ResourceTencentCloudEmrCluster() *schema.Resource {
71
75
"task_resource_spec" : buildResourceSpecSchema (),
72
76
"master_count" : {
73
77
Type : schema .TypeInt ,
78
+ Computed : true ,
74
79
Optional : true ,
75
80
Description : "The number of master node." ,
76
81
},
77
82
"core_count" : {
78
83
Type : schema .TypeInt ,
84
+ Computed : true ,
79
85
Optional : true ,
80
86
Description : "The number of core node." ,
81
87
},
82
88
"task_count" : {
83
89
Type : schema .TypeInt ,
90
+ Computed : true ,
84
91
Optional : true ,
85
92
Description : "The number of core node." ,
86
93
},
87
94
"common_resource_spec" : buildResourceSpecSchema (),
88
95
"common_count" : {
89
96
Type : schema .TypeInt ,
97
+ Computed : true ,
90
98
Optional : true ,
91
99
ForceNew : true ,
92
100
Description : "The number of common node." ,
@@ -116,25 +124,50 @@ func ResourceTencentCloudEmrCluster() *schema.Resource {
116
124
Description : "The pay mode of instance. 0 represent POSTPAID_BY_HOUR, 1 represent PREPAID." ,
117
125
},
118
126
"placement" : {
119
- Type : schema .TypeMap ,
120
- Required : true ,
121
- ForceNew : true ,
127
+ Type : schema .TypeMap ,
128
+ Optional : true ,
129
+ Computed : true ,
130
+ ExactlyOneOf : []string {"placement" , "placement_info" },
131
+ Deprecated : "It will be deprecated in later versions. Use `placement_info` instead." ,
132
+ Description : "The location of the instance." ,
133
+ },
134
+ "placement_info" : {
135
+ Type : schema .TypeList ,
136
+ Optional : true ,
137
+ Computed : true ,
138
+ MaxItems : 1 ,
139
+ ExactlyOneOf : []string {"placement" , "placement_info" },
140
+ Elem : & schema.Resource {
141
+ Schema : map [string ]* schema.Schema {
142
+ "zone" : {
143
+ Type : schema .TypeString ,
144
+ Required : true ,
145
+ Description : "Zone." ,
146
+ },
147
+ "project_id" : {
148
+ Type : schema .TypeInt ,
149
+ Computed : true ,
150
+ Optional : true ,
151
+ Description : "Project id." ,
152
+ },
153
+ },
154
+ },
122
155
Description : "The location of the instance." ,
123
156
},
124
157
"time_span" : {
125
158
Type : schema .TypeInt ,
126
- Required : true ,
159
+ Optional : true ,
127
160
Description : "The length of time the instance was purchased. Use with TimeUnit.When TimeUnit is s, the parameter can only be filled in at 3600, representing a metered instance.\n When TimeUnit is m, the number filled in by this parameter indicates the length of purchase of the monthly instance of the package year, such as 1 for one month of purchase." ,
128
161
},
129
162
"time_unit" : {
130
163
Type : schema .TypeString ,
131
- Required : true ,
164
+ Optional : true ,
132
165
Description : "The unit of time in which the instance was purchased. When PayMode is 0, TimeUnit can only take values of s(second). When PayMode is 1, TimeUnit can only take the value m(month)." ,
133
166
},
134
167
"login_settings" : {
135
168
Type : schema .TypeMap ,
136
- Required : true ,
137
- ForceNew : true ,
169
+ Optional : true ,
170
+ Sensitive : true ,
138
171
Description : "Instance login settings." ,
139
172
},
140
173
"extend_fs_field" : {
@@ -178,6 +211,14 @@ func resourceTencentCloudEmrClusterUpdate(d *schema.ResourceData, meta interface
178
211
defer tccommon .LogElapsed ("resource.tencentcloud_emr_cluster.update" )()
179
212
logId := tccommon .GetLogId (tccommon .ContextNil )
180
213
ctx := context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
214
+
215
+ immutableFields := []string {"placement" , "placement_info" , "display_strategy" , "login_settings" }
216
+ for _ , f := range immutableFields {
217
+ if d .HasChange (f ) {
218
+ return fmt .Errorf ("cannot update argument `%s`" , f )
219
+ }
220
+ }
221
+
181
222
emrService := EMRService {
182
223
client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn (),
183
224
}
@@ -253,13 +294,20 @@ func resourceTencentCloudEmrClusterUpdate(d *schema.ResourceData, meta interface
253
294
if err != nil {
254
295
return err
255
296
}
256
- return nil
297
+ return resourceTencentCloudEmrClusterRead ( d , meta )
257
298
}
258
299
259
300
func resourceTencentCloudEmrClusterCreate (d * schema.ResourceData , meta interface {}) error {
260
301
defer tccommon .LogElapsed ("resource.tencentcloud_emr_cluster.create" )()
261
302
logId := tccommon .GetLogId (tccommon .ContextNil )
262
303
ctx := context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
304
+ immutableFields := []string {"time_unit" , "time_span" , "login_settings" }
305
+ for _ , f := range immutableFields {
306
+ if _ , ok := d .GetOkExists (f ); ! ok {
307
+ return fmt .Errorf ("Argument `%s` must be set" , f )
308
+ }
309
+ }
310
+
263
311
emrService := EMRService {
264
312
client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn (),
265
313
}
@@ -272,6 +320,8 @@ func resourceTencentCloudEmrClusterCreate(d *schema.ResourceData, meta interface
272
320
var displayStrategy string
273
321
if v , ok := d .GetOk ("display_strategy" ); ok {
274
322
displayStrategy = v .(string )
323
+ } else {
324
+ displayStrategy = "clusterList"
275
325
}
276
326
err = resource .Retry (10 * tccommon .ReadRetryTimeout , func () * resource.RetryError {
277
327
clusters , err := emrService .DescribeInstancesById (ctx , instanceId , displayStrategy )
@@ -299,7 +349,7 @@ func resourceTencentCloudEmrClusterCreate(d *schema.ResourceData, meta interface
299
349
return err
300
350
}
301
351
302
- return nil
352
+ return resourceTencentCloudEmrClusterRead ( d , meta )
303
353
}
304
354
305
355
func resourceTencentCloudEmrClusterDelete (d * schema.ResourceData , meta interface {}) error {
@@ -376,8 +426,9 @@ func resourceTencentCloudEmrClusterRead(d *schema.ResourceData, meta interface{}
376
426
client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn (),
377
427
}
378
428
instanceId := d .Id ()
429
+ var instance * emr.ClusterInstancesInfo
379
430
err := resource .Retry (tccommon .ReadRetryTimeout , func () * resource.RetryError {
380
- _ , err := emrService .DescribeInstancesById (ctx , instanceId , DisplayStrategyIsclusterList )
431
+ result , err := emrService .DescribeInstancesById (ctx , instanceId , DisplayStrategyIsclusterList )
381
432
382
433
if e , ok := err .(* errors.TencentCloudSDKError ); ok {
383
434
if e .GetCode () == "InternalError.ClusterNotFound" {
@@ -388,12 +439,191 @@ func resourceTencentCloudEmrClusterRead(d *schema.ResourceData, meta interface{}
388
439
if err != nil {
389
440
return resource .RetryableError (err )
390
441
}
442
+
443
+ if len (result ) > 0 {
444
+ instance = result [0 ]
445
+ }
446
+
391
447
return nil
392
448
})
449
+
393
450
if err != nil {
394
451
return err
395
452
}
396
453
454
+ _ = d .Set ("instance_id" , instanceId )
455
+ if instance != nil {
456
+ _ = d .Set ("product_id" , instance .ProductId )
457
+ _ = d .Set ("vpc_settings" , map [string ]interface {}{
458
+ "vpc_id" : * instance .UniqVpcId ,
459
+ "subnet_id" : * instance .UniqSubnetId ,
460
+ })
461
+ if instance .Config != nil {
462
+ if instance .Config .SoftInfo != nil {
463
+ _ = d .Set ("softwares" , helper .PStrings (instance .Config .SoftInfo ))
464
+ }
465
+
466
+ if instance .Config .SupportHA != nil {
467
+ if * instance .Config .SupportHA {
468
+ _ = d .Set ("support_ha" , 1 )
469
+ } else {
470
+ _ = d .Set ("support_ha" , 0 )
471
+ }
472
+ }
473
+
474
+ if instance .Config .SecurityGroup != nil {
475
+ _ = d .Set ("sg_id" , instance .Config .SecurityGroup )
476
+ }
477
+ resourceSpec := make (map [string ]interface {})
478
+
479
+ var masterCount int64
480
+ if instance .Config .MasterNodeSize != nil {
481
+ masterCount = * instance .Config .MasterNodeSize
482
+ resourceSpec ["master_count" ] = masterCount
483
+ }
484
+ if masterCount != 0 && instance .Config .MasterResource != nil {
485
+ masterResource := instance .Config .MasterResource
486
+ masterResourceSpec := make (map [string ]interface {})
487
+ if masterResource .MemSize != nil {
488
+ masterResourceSpec ["mem_size" ] = * masterResource .MemSize
489
+ }
490
+ if masterResource .Cpu != nil {
491
+ masterResourceSpec ["cpu" ] = * masterResource .Cpu
492
+ }
493
+ if masterResource .DiskSize != nil {
494
+ masterResourceSpec ["disk_size" ] = * masterResource .DiskSize
495
+ }
496
+ if masterResource .DiskType != nil {
497
+ masterResourceSpec ["disk_type" ] = * masterResource .DiskType
498
+ }
499
+ if masterResource .Spec != nil {
500
+ masterResourceSpec ["spec" ] = * masterResource .Spec
501
+ }
502
+ if masterResource .StorageType != nil {
503
+ masterResourceSpec ["storage_type" ] = * masterResource .StorageType
504
+ }
505
+ if masterResource .RootSize != nil {
506
+ masterResourceSpec ["root_size" ] = * masterResource .RootSize
507
+ }
508
+ resourceSpec ["master_resource_spec" ] = []interface {}{masterResourceSpec }
509
+ }
510
+
511
+ var coreCount int64
512
+ if instance .Config .CoreNodeSize != nil {
513
+ coreCount = * instance .Config .CoreNodeSize
514
+ resourceSpec ["core_count" ] = coreCount
515
+ }
516
+ if coreCount != 0 && instance .Config .CoreResource != nil {
517
+ coreResource := instance .Config .CoreResource
518
+ coreResourceSpec := make (map [string ]interface {})
519
+ if coreResource .MemSize != nil {
520
+ coreResourceSpec ["mem_size" ] = * coreResource .MemSize
521
+ }
522
+ if coreResource .Cpu != nil {
523
+ coreResourceSpec ["cpu" ] = * coreResource .Cpu
524
+ }
525
+ if coreResource .DiskSize != nil {
526
+ coreResourceSpec ["disk_size" ] = * coreResource .DiskSize
527
+ }
528
+ if coreResource .DiskType != nil {
529
+ coreResourceSpec ["disk_type" ] = * coreResource .DiskType
530
+ }
531
+ if coreResource .Spec != nil {
532
+ coreResourceSpec ["spec" ] = * coreResource .Spec
533
+ }
534
+ if coreResource .StorageType != nil {
535
+ coreResourceSpec ["storage_type" ] = * coreResource .StorageType
536
+ }
537
+ if coreResource .RootSize != nil {
538
+ coreResourceSpec ["root_size" ] = * coreResource .RootSize
539
+ }
540
+ resourceSpec ["core_resource_spec" ] = []interface {}{coreResourceSpec }
541
+ }
542
+
543
+ var taskCount int64
544
+ if instance .Config .TaskNodeSize != nil {
545
+ taskCount = * instance .Config .TaskNodeSize
546
+ resourceSpec ["task_count" ] = taskCount
547
+ }
548
+ if taskCount != 0 && instance .Config .TaskResource != nil {
549
+ taskResource := instance .Config .TaskResource
550
+ taskResourceSpec := make (map [string ]interface {})
551
+ if taskResource .MemSize != nil {
552
+ taskResourceSpec ["mem_size" ] = * taskResource .MemSize
553
+ }
554
+ if taskResource .Cpu != nil {
555
+ taskResourceSpec ["cpu" ] = * taskResource .Cpu
556
+ }
557
+ if taskResource .DiskSize != nil {
558
+ taskResourceSpec ["disk_size" ] = * taskResource .DiskSize
559
+ }
560
+ if taskResource .DiskType != nil {
561
+ taskResourceSpec ["disk_type" ] = * taskResource .DiskType
562
+ }
563
+ if taskResource .Spec != nil {
564
+ taskResourceSpec ["spec" ] = * taskResource .Spec
565
+ }
566
+ if taskResource .StorageType != nil {
567
+ taskResourceSpec ["storage_type" ] = * taskResource .StorageType
568
+ }
569
+ if taskResource .RootSize != nil {
570
+ taskResourceSpec ["root_size" ] = * taskResource .RootSize
571
+ }
572
+ resourceSpec ["task_resource_spec" ] = []interface {}{taskResourceSpec }
573
+ }
574
+
575
+ var commonCount int64
576
+ if instance .Config .ComNodeSize != nil {
577
+ commonCount = * instance .Config .ComNodeSize
578
+ resourceSpec ["common_count" ] = commonCount
579
+ }
580
+ if commonCount != 0 && instance .Config .ComResource != nil {
581
+ comResource := instance .Config .ComResource
582
+ comResourceSpec := make (map [string ]interface {})
583
+ if comResource .MemSize != nil {
584
+ comResourceSpec ["mem_size" ] = * comResource .MemSize
585
+ }
586
+ if comResource .Cpu != nil {
587
+ comResourceSpec ["cpu" ] = * comResource .Cpu
588
+ }
589
+ if comResource .DiskSize != nil {
590
+ comResourceSpec ["disk_size" ] = * comResource .DiskSize
591
+ }
592
+ if comResource .DiskType != nil {
593
+ comResourceSpec ["disk_type" ] = * comResource .DiskType
594
+ }
595
+ if comResource .Spec != nil {
596
+ comResourceSpec ["spec" ] = * comResource .Spec
597
+ }
598
+ if comResource .StorageType != nil {
599
+ comResourceSpec ["storage_type" ] = * comResource .StorageType
600
+ }
601
+ if comResource .RootSize != nil {
602
+ comResourceSpec ["root_size" ] = * comResource .RootSize
603
+ }
604
+ resourceSpec ["common_resource_spec" ] = []interface {}{comResourceSpec }
605
+ }
606
+
607
+ _ = d .Set ("resource_spec" , []interface {}{resourceSpec })
608
+ }
609
+
610
+ _ = d .Set ("instance_name" , instance .ClusterName )
611
+ _ = d .Set ("pay_mode" , instance .ChargeType )
612
+ placement := map [string ]interface {}{
613
+ "zone" : * instance .Zone ,
614
+ "project_id" : * instance .ProjectId ,
615
+ }
616
+ _ = d .Set ("placement" , map [string ]interface {}{
617
+ "zone" : * instance .Zone ,
618
+ })
619
+ _ = d .Set ("placement_info" , []interface {}{placement })
620
+ if instance .MasterIp != nil {
621
+ _ = d .Set ("need_master_wan" , "NEED_MASTER_WAN" )
622
+ } else {
623
+ _ = d .Set ("need_master_wan" , "NOT_NEED_MASTER_WAN" )
624
+ }
625
+ }
626
+
397
627
tagService := svctag .NewTagService (meta .(tccommon.ProviderMeta ).GetAPIV3Conn ())
398
628
region := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().Region
399
629
tags , err := tagService .DescribeResourceTags (ctx , "emr" , "emr-instance" , region , d .Id ())
0 commit comments