Skip to content

Commit 3d1d0e8

Browse files
authored
ckafka support max_message_byte (#1819)
* ckafka support max_message_byte * ckafka support max_message_byte
1 parent dde510a commit 3d1d0e8

File tree

4 files changed

+128
-9
lines changed

4 files changed

+128
-9
lines changed

.changelog/1819.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_instance: support set `max_message_byte`
3+
```

tencentcloud/resource_tc_ckafka_instance.go

Lines changed: 117 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,49 @@ func resourceTencentCloudCkafkaInstance() *schema.Resource {
289289
Computed: true,
290290
Description: "Bandwidth of the public network.",
291291
},
292+
//"dynamic_disk_config": {
293+
// Type: schema.TypeList,
294+
// Optional: true,
295+
// MaxItems: 1,
296+
// Computed: true,
297+
// Elem: &schema.Resource{
298+
// Schema: map[string]*schema.Schema{
299+
// "enable": {
300+
// Type: schema.TypeInt,
301+
// Optional: true,
302+
// Computed: true,
303+
// Description: "Whether to the dynamic disk expansion configuration is enabled." +
304+
// "0: disabled; 1: enabled.",
305+
// },
306+
// "disk_quota_percentage": {
307+
// Type: schema.TypeInt,
308+
// Optional: true,
309+
// Computed: true,
310+
// Description: "Disk quota threshold (in percentage) for triggering the automatic disk expansion event.",
311+
// },
312+
// "step_forward_percentage": {
313+
// Type: schema.TypeInt,
314+
// Optional: true,
315+
// Computed: true,
316+
// Description: "Percentage of dynamic disk expansion each time.",
317+
// },
318+
// "max_disk_space": {
319+
// Type: schema.TypeInt,
320+
// Optional: true,
321+
// Computed: true,
322+
// Description: "Max scale disk size, in GB.",
323+
// },
324+
// },
325+
// },
326+
// Description: "Dynamic disk expansion policy configuration.",
327+
//},
328+
"max_message_byte": {
329+
Type: schema.TypeInt,
330+
Optional: true,
331+
Computed: true,
332+
ValidateFunc: validateIntegerInRange(1024, 12*1024*1024),
333+
Description: "The size of a single message in bytes at the instance level. Value range: `1024 - 12*1024*1024 bytes (i.e., 1KB-12MB).",
334+
},
292335
"vip": {
293336
Type: schema.TypeString,
294337
Computed: true,
@@ -429,6 +472,7 @@ func resourceTencentCloudCkafkaInstanceCreate(d *schema.ResourceData, meta inter
429472
modifyRequest.InstanceId = instanceId
430473

431474
if v, ok := d.GetOk("msg_retention_time"); ok {
475+
needModify = true
432476
retentionTime := int64(v.(int))
433477
modifyRequest.MsgRetentionTime = helper.Int64(retentionTime)
434478
}
@@ -486,10 +530,38 @@ func resourceTencentCloudCkafkaInstanceCreate(d *schema.ResourceData, meta inter
486530
modifyRequest.PublicNetwork = helper.Int64(int64(v.(int)))
487531
}
488532

533+
//if v, ok := d.GetOk("dynamic_disk_config"); ok {
534+
// needModify = true
535+
// dynamic := make([]*ckafka.DynamicDiskConfig, 0, 10)
536+
// for _, item := range v.([]interface{}) {
537+
// dMap := item.(map[string]interface{})
538+
// dynamicInfo := ckafka.DynamicDiskConfig{}
539+
// if enable, ok := dMap["enable"]; ok {
540+
// dynamicInfo.Enable = helper.Int64(int64(enable.(int)))
541+
// }
542+
// if stepForwardPercentage, ok := dMap["step_forward_percentage"]; ok {
543+
// dynamicInfo.StepForwardPercentage = helper.Int64(int64(stepForwardPercentage.(int)))
544+
// }
545+
// if diskQuotaPercentage, ok := dMap["disk_quota_percentage"]; ok {
546+
// dynamicInfo.DiskQuotaPercentage = helper.Int64(int64(diskQuotaPercentage.(int)))
547+
// }
548+
// if maxDiskSpace, ok := dMap["max_disk_space"]; ok {
549+
// dynamicInfo.MaxDiskSpace = helper.Int64(int64(maxDiskSpace.(int)))
550+
// }
551+
// dynamic = append(dynamic, &dynamicInfo)
552+
// }
553+
// modifyRequest.DynamicDiskConfig = dynamic[0]
554+
//}
555+
556+
if v, ok := d.GetOkExists("max_message_byte"); ok {
557+
needModify = true
558+
modifyRequest.MaxMessageByte = helper.Uint64(uint64(v.(int)))
559+
}
560+
489561
if needModify {
490-
error := service.ModifyCkafkaInstanceAttributes(ctx, modifyRequest)
491-
if error != nil {
492-
return fmt.Errorf("[API]Set kafka instance attributes fail, reason:%s", error.Error())
562+
err := service.ModifyCkafkaInstanceAttributes(ctx, modifyRequest)
563+
if err != nil {
564+
return fmt.Errorf("[API]Set kafka instance attributes fail, reason:%s", err.Error())
493565
}
494566
}
495567

@@ -633,6 +705,15 @@ func resourceTencentCloudCkafkaInstanceRead(d *schema.ResourceData, meta interfa
633705
_ = d.Set("dynamic_retention_config", dynamicConfig)
634706
_ = d.Set("public_network", attr.PublicNetwork)
635707

708+
//dynamicDiskConfig := make([]map[string]interface{}, 0)
709+
//dynamicDiskConfig = append(dynamicDiskConfig, map[string]interface{}{
710+
// "enable": attr.DynamicDiskConfig.Enable,
711+
// "disk_quota_percentage": attr.DynamicDiskConfig.DiskQuotaPercentage,
712+
// "step_forward_percentage": attr.DynamicDiskConfig.StepForwardPercentage,
713+
// "max_disk_space": attr.DynamicDiskConfig.MaxDiskSpace,
714+
//})
715+
//_ = d.Set("dynamic_disk_config", dynamicDiskConfig)
716+
636717
return nil
637718
})
638719
if err != nil {
@@ -729,9 +810,39 @@ func resourceTencentCloudCkafkaInstanceUpdate(d *schema.ResourceData, meta inter
729810
}
730811
}
731812

732-
error := service.ModifyCkafkaInstanceAttributes(ctx, request)
733-
if error != nil {
734-
return fmt.Errorf("[API]Set kafka instance attributes fail, reason:%s", error.Error())
813+
//if d.HasChange("dynamic_disk_config") {
814+
// if v, ok := d.GetOk("dynamic_disk_config"); ok {
815+
// dynamic := make([]*ckafka.DynamicDiskConfig, 0, 10)
816+
// for _, item := range v.([]interface{}) {
817+
// dMap := item.(map[string]interface{})
818+
// dynamicInfo := ckafka.DynamicDiskConfig{}
819+
// if enable, ok := dMap["enable"]; ok {
820+
// dynamicInfo.Enable = helper.Int64(int64(enable.(int)))
821+
// }
822+
// if stepForwardPercentage, ok := dMap["step_forward_percentage"]; ok {
823+
// dynamicInfo.StepForwardPercentage = helper.Int64(int64(stepForwardPercentage.(int)))
824+
// }
825+
// if diskQuotaPercentage, ok := dMap["disk_quota_percentage"]; ok {
826+
// dynamicInfo.DiskQuotaPercentage = helper.Int64(int64(diskQuotaPercentage.(int)))
827+
// }
828+
// if maxDiskSpace, ok := dMap["max_disk_space"]; ok {
829+
// dynamicInfo.MaxDiskSpace = helper.Int64(int64(maxDiskSpace.(int)))
830+
// }
831+
// dynamic = append(dynamic, &dynamicInfo)
832+
// }
833+
// request.DynamicDiskConfig = dynamic[0]
834+
// }
835+
//}
836+
837+
if d.HasChange("max_message_byte") {
838+
if v, ok := d.GetOkExists("max_message_byte"); ok {
839+
request.MaxMessageByte = helper.Uint64(uint64(v.(int)))
840+
}
841+
}
842+
843+
err := service.ModifyCkafkaInstanceAttributes(ctx, request)
844+
if err != nil {
845+
return fmt.Errorf("[API]Set kafka instance attributes fail, reason:%s", err.Error())
735846
}
736847

737848
if d.HasChange("band_width") || d.HasChange("disk_size") || d.HasChange("partition") {

tencentcloud/resource_tc_ckafka_instance_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func TestAccTencentCloudCkafkaInstanceResource(t *testing.T) {
2424
resource.TestCheckResourceAttr("tencentcloud_ckafka_instance.kafka_instance", "zone_id", "100003"),
2525
resource.TestCheckResourceAttr("tencentcloud_ckafka_instance.kafka_instance", "period", "1"),
2626
resource.TestCheckResourceAttr("tencentcloud_ckafka_instance.kafka_instance", "msg_retention_time", "1300"),
27+
resource.TestCheckResourceAttr("tencentcloud_ckafka_instance.kafka_instance", "max_message_byte", "1024"),
2728
resource.TestCheckResourceAttr("tencentcloud_ckafka_instance.kafka_instance", "renew_flag", "0"),
2829
resource.TestCheckResourceAttr("tencentcloud_ckafka_instance.kafka_instance", "kafka_version", "1.1.1"),
2930
resource.TestCheckResourceAttr("tencentcloud_ckafka_instance.kafka_instance", "disk_size", "500"),
@@ -40,6 +41,7 @@ func TestAccTencentCloudCkafkaInstanceResource(t *testing.T) {
4041
resource.TestCheckResourceAttr("tencentcloud_ckafka_instance.kafka_instance", "zone_id", "100003"),
4142
resource.TestCheckResourceAttr("tencentcloud_ckafka_instance.kafka_instance", "period", "1"),
4243
resource.TestCheckResourceAttr("tencentcloud_ckafka_instance.kafka_instance", "msg_retention_time", "1200"),
44+
resource.TestCheckResourceAttr("tencentcloud_ckafka_instance.kafka_instance", "max_message_byte", "1025"),
4345
resource.TestCheckResourceAttr("tencentcloud_ckafka_instance.kafka_instance", "renew_flag", "0"),
4446
resource.TestCheckResourceAttr("tencentcloud_ckafka_instance.kafka_instance", "kafka_version", "1.1.1"),
4547
resource.TestCheckResourceAttr("tencentcloud_ckafka_instance.kafka_instance", "disk_size", "500"),
@@ -50,7 +52,7 @@ func TestAccTencentCloudCkafkaInstanceResource(t *testing.T) {
5052
ResourceName: "tencentcloud_ckafka_instance.kafka_instance",
5153
ImportState: true,
5254
ImportStateVerify: true,
53-
ImportStateVerifyIgnore: []string{"period"},
55+
ImportStateVerifyIgnore: []string{"period", "max_message_byte"},
5456
},
5557
},
5658
})
@@ -76,7 +78,7 @@ func TestAccTencentCloudCkafkaInstanceMAZResource(t *testing.T) {
7678
ResourceName: "tencentcloud_ckafka_instance.kafka_instance",
7779
ImportState: true,
7880
ImportStateVerify: true,
79-
ImportStateVerifyIgnore: []string{"period"},
81+
ImportStateVerifyIgnore: []string{"period", "max_message_byte"},
8082
},
8183
},
8284
})
@@ -102,7 +104,7 @@ func TestAccTencentCloudCkafkaInstanceTypeResource(t *testing.T) {
102104
ResourceName: "tencentcloud_ckafka_instance.kafka_instance",
103105
ImportState: true,
104106
ImportStateVerify: true,
105-
ImportStateVerifyIgnore: []string{"period"},
107+
ImportStateVerifyIgnore: []string{"period", "max_message_byte"},
106108
},
107109
},
108110
})
@@ -173,6 +175,7 @@ resource "tencentcloud_ckafka_instance" "kafka_instance" {
173175
vpc_id = var.vpc_id
174176
subnet_id = var.subnet_id
175177
msg_retention_time = 1300
178+
max_message_byte = 1024
176179
renew_flag = 0
177180
kafka_version = "1.1.1"
178181
disk_size = 500
@@ -199,6 +202,7 @@ resource "tencentcloud_ckafka_instance" "kafka_instance" {
199202
vpc_id = var.vpc_id
200203
subnet_id = var.subnet_id
201204
msg_retention_time = 1200
205+
max_message_byte = 1025
202206
renew_flag = 0
203207
kafka_version = "1.1.1"
204208
disk_size = 500

website/docs/r/ckafka_instance.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ The following arguments are supported:
6565
* `dynamic_retention_config` - (Optional, List) Dynamic message retention policy configuration.
6666
* `instance_type` - (Optional, Int) Description of instance type. `profession`: 1, `standard`: 1(general), 2(standard), 3(advanced), 4(capacity), 5(specialized-1), 6(specialized-2), 7(specialized-3), 8(specialized-4), 9(exclusive).
6767
* `kafka_version` - (Optional, String) Kafka version (0.10.2/1.1.1/2.4.1).
68+
* `max_message_byte` - (Optional, Int) The size of a single message in bytes at the instance level. Value range: `1024 - 12*1024*1024 bytes (i.e., 1KB-12MB).
6869
* `msg_retention_time` - (Optional, Int) The maximum retention time of instance logs, in minutes. the default is 10080 (7 days), the maximum is 30 days, and the default 0 is not filled, which means that the log retention time recovery policy is not enabled.
6970
* `multi_zone_flag` - (Optional, Bool) Indicates whether the instance is multi zones. NOTE: if set to `true`, `zone_ids` must set together.
7071
* `partition` - (Optional, Int) Partition Size. Its interval varies with bandwidth, and the input must be within the interval, which can be viewed through the control. If it is not within the interval, the plan will cause a change when first created.

0 commit comments

Comments
 (0)