Skip to content

Commit e2bbe26

Browse files
authored
ckafka tag support change (#1312)
1 parent 8fef69c commit e2bbe26

File tree

3 files changed

+59
-7
lines changed

3 files changed

+59
-7
lines changed

tencentcloud/resource_tc_ckafka_instance.go

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,12 @@ func resourceTencentCloudCkafkaInstance() *schema.Resource {
164164
Elem: &schema.Schema{Type: schema.TypeInt},
165165
},
166166
"tags": {
167-
Type: schema.TypeList,
168-
Optional: true,
169-
Description: "Partition size, the professional version does not need tag.",
167+
Type: schema.TypeList,
168+
Optional: true,
169+
Computed: true,
170+
Deprecated: "It has been deprecated from version 1.78.5, because it do not support change. Use `tag_set` instead.",
171+
ConflictsWith: []string{"tag_set"},
172+
Description: "Tags of instance. Partition size, the professional version does not need tag.",
170173
Elem: &schema.Resource{
171174
Schema: map[string]*schema.Schema{
172175
"key": {
@@ -182,6 +185,13 @@ func resourceTencentCloudCkafkaInstance() *schema.Resource {
182185
},
183186
},
184187
},
188+
"tag_set": {
189+
Type: schema.TypeMap,
190+
Optional: true,
191+
Computed: true,
192+
Description: "Tag set of instance.",
193+
ConflictsWith: []string{"tags"},
194+
},
185195
"disk_type": {
186196
Type: schema.TypeString,
187197
Optional: true,
@@ -461,6 +471,18 @@ func resourceTencentCloudCkafkaInstanceCreate(d *schema.ResourceData, meta inter
461471
return fmt.Errorf("[API]Set kafka instance attributes fail, reason:%s", error.Error())
462472
}
463473
}
474+
475+
client := meta.(*TencentCloudClient).apiV3Conn
476+
tagService := TagService{client: client}
477+
region := client.Region
478+
479+
if tags := helper.GetTags(d, "tag_set"); len(tags) > 0 {
480+
resourceName := BuildTagResourceName("ckafka", "ckafkaId", region, *instanceId)
481+
if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil {
482+
return err
483+
}
484+
}
485+
464486
return resourceTencentCloudCkafkaInstanceRead(d, meta)
465487
}
466488

@@ -535,6 +557,17 @@ func resourceTencentCloudCkafkaInstanceRead(d *schema.ResourceData, meta interfa
535557
})
536558
}
537559
_ = d.Set("tags", tagSets)
560+
561+
client := meta.(*TencentCloudClient).apiV3Conn
562+
tagService := TagService{client: client}
563+
region := client.Region
564+
565+
tags, err := tagService.DescribeResourceTags(ctx, "ckafka", "ckafkaId", region, instanceId)
566+
if err != nil {
567+
return err
568+
}
569+
_ = d.Set("tag_set", tags)
570+
538571
_ = d.Set("disk_type", info.DiskType)
539572
_ = d.Set("rebalance_time", info.RebalanceTime)
540573

@@ -591,11 +624,10 @@ func resourceTencentCloudCkafkaInstanceUpdate(d *schema.ResourceData, meta inter
591624
}
592625

593626
if d.HasChange("zone_id") || d.HasChange("period") || d.HasChange("vpc_id") || d.HasChange("subnet_id") ||
594-
d.HasChange("renew_flag") || d.HasChange("kafka_version") || d.HasChange("multi_zone_flag") || d.HasChange("zone_ids") ||
595-
d.HasChange("tags") || d.HasChange("disk_type") {
627+
d.HasChange("renew_flag") || d.HasChange("kafka_version") || d.HasChange("multi_zone_flag") || d.HasChange("zone_ids") || d.HasChange("disk_type") {
596628

597629
return fmt.Errorf("parms like 'zone_id | period | vpc_id | subnet_id | renew_flag | " +
598-
"kafka_version | multi_zone_flag | zone_ids | tags | disk_type', do not support change now.")
630+
"kafka_version | multi_zone_flag | zone_id | disk_type', do not support change now.")
599631
}
600632

601633
instanceId := d.Id()
@@ -704,6 +736,21 @@ func resourceTencentCloudCkafkaInstanceUpdate(d *schema.ResourceData, meta inter
704736
}
705737
}
706738

739+
if d.HasChange("tag_set") {
740+
741+
client := meta.(*TencentCloudClient).apiV3Conn
742+
tagService := TagService{client: client}
743+
region := client.Region
744+
745+
oldTags, newTags := d.GetChange("tag_set")
746+
replaceTags, deleteTags := diffTags(oldTags.(map[string]interface{}), newTags.(map[string]interface{}))
747+
748+
resourceName := BuildTagResourceName("ckafka", "ckafkaId", region, instanceId)
749+
if err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags); err != nil {
750+
return err
751+
}
752+
}
753+
707754
return resourceTencentCloudCkafkaInstanceRead(d, meta)
708755
}
709756

tencentcloud/resource_tc_ckafka_instance_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ resource "tencentcloud_ckafka_instance" "kafka_instance" {
188188
dynamic_retention_config {
189189
enable = 1
190190
}
191+
192+
tag_set = {
193+
createdBy = "terraform"
194+
}
191195
}
192196
`
193197

website/docs/r/ckafka_instance.html.markdown

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ The following arguments are supported:
7272
* `public_network` - (Optional, Int) Timestamp.
7373
* `rebalance_time` - (Optional, Int) Modification of the rebalancing time after upgrade.
7474
* `renew_flag` - (Optional, Int) Prepaid automatic renewal mark, 0 means the default state, the initial state, 1 means automatic renewal, 2 means clear no automatic renewal (user setting).
75-
* `tags` - (Optional, List) Partition size, the professional version does not need tag.
75+
* `tag_set` - (Optional, Map) Tag set of instance.
76+
* `tags` - (Optional, List, **Deprecated**) It has been deprecated from version 1.78.5, because it do not support change. Use `tag_set` instead. Tags of instance. Partition size, the professional version does not need tag.
7677
* `zone_ids` - (Optional, Set: [`Int`]) List of available zone id. NOTE: this argument must set together with `multi_zone_flag`.
7778

7879
The `config` object supports the following:

0 commit comments

Comments
 (0)