Skip to content

Commit 262bc26

Browse files
authored
ckafka support set instance type (#1589)
* ckafka support set instance type * add changelog
1 parent 64c643f commit 262bc26

File tree

5 files changed

+87
-3
lines changed

5 files changed

+87
-3
lines changed

.changelog/1589.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 `instance_type`
3+
```

tencentcloud/extension_ckafka.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ const (
55
CKAFKA_ACL_PRINCIPAL_STR = "User:"
66
)
77

8+
var CKAFKA_INSTANCE_TYPE = map[string]int64{
9+
"general": 1,
10+
"standard": 2,
11+
"advanced": 3,
12+
"capacity": 4,
13+
"specialized-1": 5,
14+
"specialized-2": 6,
15+
"specialized-3": 7,
16+
"specialized-4": 8,
17+
"exclusive": 9,
18+
}
19+
820
var CKAFKA_ACL_RESOURCE_TYPE = map[string]int64{
921
"UNKNOWN": 0,
1022
"ANY": 1,

tencentcloud/resource_tc_ckafka_instance.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ func resourceTencentCloudCkafkaInstance() *schema.Resource {
108108
Optional: true,
109109
Description: "Prepaid purchase time, such as 1, is one month.",
110110
},
111+
"instance_type": {
112+
Type: schema.TypeInt,
113+
Optional: true,
114+
Computed: true,
115+
ValidateFunc: validateAllowedIntValue([]int{1, 2, 3, 4, 5, 6, 7, 8, 9}),
116+
Description: "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).",
117+
},
111118
"vpc_id": {
112119
Type: schema.TypeString,
113120
Optional: true,
@@ -317,6 +324,10 @@ func resourceTencentCloudCkafkaInstanceCreate(d *schema.ResourceData, meta inter
317324
request.Period = helper.String(fmt.Sprintf("%dm", period))
318325
request.InstanceType = helper.IntInt64(1)
319326

327+
if v, ok := d.GetOkExists("instance_type"); ok {
328+
request.InstanceType = helper.IntInt64(v.(int))
329+
}
330+
320331
if v, ok := d.GetOk("specifications_type"); ok {
321332
request.SpecificationsType = helper.String(v.(string))
322333
}
@@ -551,8 +562,10 @@ func resourceTencentCloudCkafkaInstanceRead(d *schema.ResourceData, meta interfa
551562
_ = d.Set("partition", info.MaxPartitionNumber)
552563
if *info.InstanceType == "profession" {
553564
_ = d.Set("specifications_type", "profession")
565+
_ = d.Set("instance_type", 1)
554566
} else {
555567
_ = d.Set("specifications_type", "standard")
568+
_ = d.Set("instance_type", CKAFKA_INSTANCE_TYPE[*info.InstanceType])
556569
}
557570

558571
if len(info.ZoneIds) > 1 {
@@ -642,7 +655,7 @@ func resourceTencentCloudCkafkaInstanceUpdate(d *schema.ResourceData, meta inter
642655
"zone_id", "period", "vpc_id",
643656
"subnet_id", "renew_flag", "kafka_version",
644657
"multi_zone_flag", "zone_ids", "disk_type",
645-
"specifications_type",
658+
"specifications_type", "instance_type",
646659
}
647660

648661
for _, v := range immutableArgs {

tencentcloud/resource_tc_ckafka_instance_test.go

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/hashicorp/terraform-plugin-sdk/terraform"
1010
)
1111

12-
func TestAccTencentCloudCkafkaInstance(t *testing.T) {
12+
func TestAccTencentCloudCkafkaInstanceResource(t *testing.T) {
1313
t.Parallel()
1414
resource.Test(t, resource.TestCase{
1515
PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_PREPAY) },
@@ -56,7 +56,7 @@ func TestAccTencentCloudCkafkaInstance(t *testing.T) {
5656
})
5757
}
5858

59-
func TestAccTencentCloudKafkaInstanceMAZ(t *testing.T) {
59+
func TestAccTencentCloudCkafkaInstanceMAZResource(t *testing.T) {
6060
t.Parallel()
6161
resource.Test(t, resource.TestCase{
6262
PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_PREPAY) },
@@ -82,6 +82,32 @@ func TestAccTencentCloudKafkaInstanceMAZ(t *testing.T) {
8282
})
8383
}
8484

85+
func TestAccTencentCloudCkafkaInstanceTypeResource(t *testing.T) {
86+
t.Parallel()
87+
resource.Test(t, resource.TestCase{
88+
PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_PREPAY) },
89+
Providers: testAccProviders,
90+
CheckDestroy: testAccTencentCloudKafkaInstanceDestroy,
91+
Steps: []resource.TestStep{
92+
{
93+
Config: testAccKafkaInstanceType,
94+
Check: resource.ComposeTestCheckFunc(
95+
testAccCheckKafkaInstanceExists("tencentcloud_ckafka_instance.kafka_instance"),
96+
resource.TestCheckResourceAttr("tencentcloud_ckafka_instance.kafka_instance", "instance_name", "ckafka-instance-type-tf-test"),
97+
resource.TestCheckResourceAttr("tencentcloud_ckafka_instance.kafka_instance", "specifications_type", "standard"),
98+
resource.TestCheckResourceAttr("tencentcloud_ckafka_instance.kafka_instance", "instance_type", "2"),
99+
),
100+
},
101+
{
102+
ResourceName: "tencentcloud_ckafka_instance.kafka_instance",
103+
ImportState: true,
104+
ImportStateVerify: true,
105+
ImportStateVerifyIgnore: []string{"period"},
106+
},
107+
},
108+
})
109+
}
110+
85111
func testAccTencentCloudKafkaInstanceDestroy(s *terraform.State) error {
86112
logId := getLogId(contextNil)
87113
ctx := context.WithValue(context.TODO(), logIdKey, logId)
@@ -211,6 +237,35 @@ resource "tencentcloud_ckafka_instance" "kafka_instance" {
211237
disk_type = "CLOUD_BASIC"
212238
213239
240+
config {
241+
auto_create_topic_enable = true
242+
default_num_partitions = 3
243+
default_replication_factor = 3
244+
}
245+
246+
dynamic_retention_config {
247+
enable = 1
248+
}
249+
}
250+
`
251+
252+
const testAccKafkaInstanceType = defaultKafkaVariable + `
253+
resource "tencentcloud_ckafka_instance" "kafka_instance" {
254+
instance_name = "ckafka-instance-type-tf-test"
255+
zone_id = 100003
256+
period = 1
257+
vpc_id = var.vpc_id
258+
subnet_id = var.subnet_id
259+
msg_retention_time = 1300
260+
renew_flag = 0
261+
kafka_version = "1.1.1"
262+
disk_size = 1000
263+
disk_type = "CLOUD_BASIC"
264+
265+
specifications_type = "standard"
266+
instance_type = 2
267+
268+
214269
config {
215270
auto_create_topic_enable = true
216271
default_num_partitions = 3

website/docs/r/ckafka_instance.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ The following arguments are supported:
6363
* `disk_size` - (Optional, Int) Disk 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.
6464
* `disk_type` - (Optional, String) Type of disk.
6565
* `dynamic_retention_config` - (Optional, List) Dynamic message retention policy configuration.
66+
* `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).
6667
* `kafka_version` - (Optional, String) Kafka version (0.10.2/1.1.1/2.4.1).
6768
* `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.
6869
* `multi_zone_flag` - (Optional, Bool) Indicates whether the instance is multi zones. NOTE: if set to `true`, `zone_ids` must set together.

0 commit comments

Comments
 (0)