Skip to content

Commit f001450

Browse files
authored
Merge pull request #1686 from tencentcloudstack/feat/ckafka_topic_support_modify_topic
topic suppport replica_num
2 parents 8ccb800 + 4151e5a commit f001450

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

.changelog/1686.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_ckafka_topic: support update `replica_num`
3+
```

tencentcloud/resource_tc_ckafka_topic.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,7 @@ func resourceTencentCloudCkafkaTopicRead(d *schema.ResourceData, meta interface{
253253
}
254254
items := strings.Split(d.Id(), FILED_SP)
255255
if len(items) < 2 {
256-
d.SetId("")
257-
return nil
256+
return fmt.Errorf("id is broken,%s", d.Id())
258257
}
259258
instanceId := items[0]
260259
topicName := items[1]
@@ -314,9 +313,16 @@ func resourceTencentCloudCkafkaTopicUpdate(d *schema.ResourceData, meta interfac
314313
ckafkcService := CkafkaService{
315314
client: meta.(*TencentCloudClient).apiV3Conn,
316315
}
316+
317+
items := strings.Split(d.Id(), FILED_SP)
318+
if len(items) < 2 {
319+
return fmt.Errorf("id is broken,%s", d.Id())
320+
}
321+
instanceId := items[0]
322+
topicName := items[1]
323+
317324
request := ckafka.NewModifyTopicAttributesRequest()
318-
instanceId := d.Get("instance_id").(string)
319-
topicName := d.Get("topic_name").(string)
325+
replicaNum := d.Get("replica_num").(int)
320326
whiteListSwitch := d.Get("enable_white_list").(bool)
321327
cleanUpPolicy := d.Get("clean_up_policy").(string)
322328
retention := d.Get("retention").(int)
@@ -332,6 +338,7 @@ func resourceTencentCloudCkafkaTopicUpdate(d *schema.ResourceData, meta interfac
332338
}
333339
request.InstanceId = &instanceId
334340
request.TopicName = &topicName
341+
request.ReplicaNum = helper.IntInt64(replicaNum)
335342
request.EnableWhiteList = helper.BoolToInt64Ptr(whiteListSwitch)
336343
request.MinInsyncReplicas = helper.IntInt64(d.Get("sync_replica_min_num").(int))
337344
request.UncleanLeaderElectionEnable = helper.BoolToInt64Ptr(d.Get("unclean_leader_election_enable").(bool))
@@ -393,8 +400,12 @@ func resourceTencentCLoudCkafkaTopicDelete(d *schema.ResourceData, meta interfac
393400
ckafkcService := CkafkaService{
394401
client: meta.(*TencentCloudClient).apiV3Conn,
395402
}
396-
instanceId := d.Get("instance_id").(string)
397-
topicName := d.Get("topic_name").(string)
403+
items := strings.Split(d.Id(), FILED_SP)
404+
if len(items) < 2 {
405+
return fmt.Errorf("id is broken,%s", d.Id())
406+
}
407+
instanceId := items[0]
408+
topicName := items[1]
398409

399410
err := ckafkcService.DeleteCkafkaTopic(ctx, instanceId, topicName)
400411
if err != nil {

tencentcloud/resource_tc_ckafka_topic_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func init() {
5757
})
5858
}
5959

60-
func TestAccTencentCloudCkafkaTopicResource(t *testing.T) {
60+
func TestAccTencentCloudCkafkaTopicResource_Basic(t *testing.T) {
6161
t.Parallel()
6262
resource.Test(t, resource.TestCase{
6363
PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_PREPAY) },
@@ -89,7 +89,8 @@ func TestAccTencentCloudCkafkaTopicResource(t *testing.T) {
8989
testAccCheckKafkaTopicInstanceExists("tencentcloud_ckafka_topic.kafka_topic"),
9090
resource.TestCheckResourceAttrSet("tencentcloud_ckafka_topic.kafka_topic", "instance_id"),
9191
resource.TestCheckResourceAttr("tencentcloud_ckafka_topic.kafka_topic", "note", "this is test topic_update"),
92-
resource.TestCheckResourceAttr("tencentcloud_ckafka_topic.kafka_topic", "partition_num", "2"),
92+
resource.TestCheckResourceAttr("tencentcloud_ckafka_topic.kafka_topic", "replica_num", "1"),
93+
resource.TestCheckResourceAttr("tencentcloud_ckafka_topic.kafka_topic", "partition_num", "3"),
9394
resource.TestCheckResourceAttr("tencentcloud_ckafka_topic.kafka_topic", "enable_white_list", "true"),
9495
resource.TestCheckResourceAttr("tencentcloud_ckafka_topic.kafka_topic", "clean_up_policy", "compact"),
9596
resource.TestCheckResourceAttr("tencentcloud_ckafka_topic.kafka_topic", "sync_replica_min_num", "2"),
@@ -195,8 +196,8 @@ resource "tencentcloud_ckafka_topic" "kafka_topic" {
195196
instance_id = var.instance_id
196197
topic_name = "ckafka-topic-tf-test"
197198
note = "this is test topic_update"
198-
replica_num = 2
199-
partition_num = 2
199+
replica_num = 1
200+
partition_num = 3
200201
enable_white_list = true
201202
ip_white_list = ["192.168.1.2"]
202203
clean_up_policy = "compact"

0 commit comments

Comments
 (0)