@@ -101,6 +101,7 @@ import (
101101 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
102102 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
103103 emr "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/emr/v20190103"
104+ "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
104105)
105106
106107func resourceTencentCloudEmrCluster () * schema.Resource {
@@ -251,6 +252,12 @@ func resourceTencentCloudEmrCluster() *schema.Resource {
251252 ForceNew : true ,
252253 Description : "The ID of the security group to which the instance belongs, in the form of sg-xxxxxxxx." ,
253254 },
255+ "tags" : {
256+ Type : schema .TypeMap ,
257+ Optional : true ,
258+ Computed : true ,
259+ Description : "Tag description list." ,
260+ },
254261 },
255262 }
256263}
@@ -269,6 +276,18 @@ func resourceTencentCloudEmrClusterUpdate(d *schema.ResourceData, meta interface
269276 if ! hasTimeUnit || ! hasTimeSpan || ! hasPayMode {
270277 return innerErr .New ("Time_unit, time_span or pay_mode must be set." )
271278 }
279+ if d .HasChange ("tags" ) {
280+ tcClient := meta .(* TencentCloudClient ).apiV3Conn
281+ tagService := & TagService {client : tcClient }
282+ oldTags , newTags := d .GetChange ("tags" )
283+ replaceTags , deleteTags := diffTags (oldTags .(map [string ]interface {}), newTags .(map [string ]interface {}))
284+ resourceName := BuildTagResourceName ("emr" , "emr-instance" , tcClient .Region , instanceId )
285+ if err := tagService .ModifyTags (ctx , resourceName , replaceTags , deleteTags ); err != nil {
286+ return err
287+ }
288+ }
289+
290+ hasChange := false
272291 request := emr .NewScaleOutInstanceRequest ()
273292 request .TimeUnit = common .StringPtr (timeUnit .(string ))
274293 request .TimeSpan = common .Uint64Ptr ((uint64 )(timeSpan .(int )))
@@ -280,16 +299,22 @@ func resourceTencentCloudEmrClusterUpdate(d *schema.ResourceData, meta interface
280299
281300 if d .HasChange ("resource_spec.0.master_count" ) {
282301 request .MasterCount = common .Uint64Ptr ((uint64 )(resourceSpec ["master_count" ].(int )))
302+ hasChange = true
283303 }
284304 if d .HasChange ("resource_spec.0.task_count" ) {
285305 request .TaskCount = common .Uint64Ptr ((uint64 )(resourceSpec ["task_count" ].(int )))
306+ hasChange = true
286307 }
287308 if d .HasChange ("resource_spec.0.core_count" ) {
288309 request .CoreCount = common .Uint64Ptr ((uint64 )(resourceSpec ["core_count" ].(int )))
310+ hasChange = true
289311 }
290312 if d .HasChange ("extend_fs_field" ) {
291313 return innerErr .New ("extend_fs_field not support update." )
292314 }
315+ if ! hasChange {
316+ return nil
317+ }
293318 _ , err := emrService .UpdateInstance (ctx , request )
294319 if err != nil {
295320 return err
@@ -364,6 +389,15 @@ func resourceTencentCloudEmrClusterCreate(d *schema.ResourceData, meta interface
364389 if err != nil {
365390 return err
366391 }
392+
393+ if tags := helper .GetTags (d , "tags" ); len (tags ) > 0 {
394+ tagService := TagService {client : meta .(* TencentCloudClient ).apiV3Conn }
395+ region := meta .(* TencentCloudClient ).apiV3Conn .Region
396+ resourceName := fmt .Sprintf ("qcs::emr:%s:uin/:emr-instance/%s" , region , d .Id ())
397+ if err := tagService .ModifyTags (ctx , resourceName , tags , nil ); err != nil {
398+ return err
399+ }
400+ }
367401 return nil
368402}
369403
@@ -458,5 +492,13 @@ func resourceTencentCloudEmrClusterRead(d *schema.ResourceData, meta interface{}
458492 if err != nil {
459493 return err
460494 }
495+
496+ tagService := TagService {client : meta .(* TencentCloudClient ).apiV3Conn }
497+ region := meta .(* TencentCloudClient ).apiV3Conn .Region
498+ tags , err := tagService .DescribeResourceTags (ctx , "emr" , "emr-instance" , region , d .Id ())
499+ if err != nil {
500+ return err
501+ }
502+ _ = d .Set ("tags" , tags )
461503 return nil
462504}
0 commit comments