Skip to content

Commit da62295

Browse files
authored
ckafka support set type (#1518)
* ckafka support set type * ckafka support set type
1 parent 05d55d5 commit da62295

File tree

3 files changed

+65
-39
lines changed

3 files changed

+65
-39
lines changed

.changelog/1518.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 create standard instance
3+
```

tencentcloud/resource_tc_ckafka_instance.go

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
/*
22
Use this resource to create ckafka instance.
33
4-
~> **NOTE:** It only support create profession and prepaid ckafka instance.
4+
~> **NOTE:** It only support create prepaid ckafka instance.
55
66
Example Usage
77
88
```hcl
99
resource "tencentcloud_ckafka_instance" "foo" {
10-
band_width = 40
11-
disk_size = 500
12-
disk_type = "CLOUD_BASIC"
13-
period = 1
14-
instance_name = "ckafka-instance-tf-test"
15-
kafka_version = "1.1.1"
16-
msg_retention_time = 1300
17-
multi_zone_flag = true
18-
partition = 800
19-
public_network = 3
20-
renew_flag = 0
21-
subnet_id = "subnet-4vwihrzk"
22-
vpc_id = "vpc-82p1t1nv"
23-
zone_id = 100006
24-
zone_ids = [
10+
band_width = 40
11+
disk_size = 500
12+
disk_type = "CLOUD_BASIC"
13+
period = 1
14+
instance_name = "ckafka-instance-tf-test"
15+
specifications_type = "profession"
16+
kafka_version = "1.1.1"
17+
msg_retention_time = 1300
18+
multi_zone_flag = true
19+
partition = 800
20+
public_network = 3
21+
renew_flag = 0
22+
subnet_id = "subnet-4vwihrzk"
23+
vpc_id = "vpc-82p1t1nv"
24+
zone_id = 100006
25+
zone_ids = [
2526
100006,
2627
100007,
2728
]
@@ -95,6 +96,13 @@ func resourceTencentCloudCkafkaInstance() *schema.Resource {
9596
return zoneIds.Contains(zoneId)
9697
},
9798
},
99+
"specifications_type": {
100+
Type: schema.TypeString,
101+
Optional: true,
102+
Default: "profession",
103+
ValidateFunc: validateAllowedStringValue([]string{"standard", "profession"}),
104+
Description: "Specifications type of instance. Allowed values are `standard`, `profession`. Default is `profession`.",
105+
},
98106
"period": {
99107
Type: schema.TypeInt,
100108
Optional: true,
@@ -307,9 +315,11 @@ func resourceTencentCloudCkafkaInstanceCreate(d *schema.ResourceData, meta inter
307315

308316
period := int64(d.Get("period").(int))
309317
request.Period = helper.String(fmt.Sprintf("%dm", period))
310-
// only support create profession instance
311-
request.InstanceType = helper.Int64(1)
312-
request.SpecificationsType = helper.String("profession")
318+
request.InstanceType = helper.IntInt64(1)
319+
320+
if v, ok := d.GetOk("specifications_type"); ok {
321+
request.SpecificationsType = helper.String(v.(string))
322+
}
313323

314324
if v, ok := d.GetOk("vpc_id"); ok {
315325
vpcId := v.(string)
@@ -539,8 +549,13 @@ func resourceTencentCloudCkafkaInstanceRead(d *schema.ResourceData, meta interfa
539549
_ = d.Set("vport", info.Vport)
540550
_ = d.Set("band_width", *bandWidth/8)
541551
_ = d.Set("partition", info.MaxPartitionNumber)
552+
if *info.InstanceType == "profession" {
553+
_ = d.Set("specifications_type", "profession")
554+
} else {
555+
_ = d.Set("specifications_type", "standard")
556+
}
542557

543-
if len(info.ZoneIds) > 0 {
558+
if len(info.ZoneIds) > 1 {
544559
_ = d.Set("multi_zone_flag", true)
545560
ids := helper.Int64sInterfaces(info.ZoneIds)
546561
idSet := schema.NewSet(func(i interface{}) int {
@@ -623,11 +638,17 @@ func resourceTencentCloudCkafkaInstanceUpdate(d *schema.ResourceData, meta inter
623638
client: meta.(*TencentCloudClient).apiV3Conn,
624639
}
625640

626-
if d.HasChange("zone_id") || d.HasChange("period") || d.HasChange("vpc_id") || d.HasChange("subnet_id") ||
627-
d.HasChange("renew_flag") || d.HasChange("kafka_version") || d.HasChange("multi_zone_flag") || d.HasChange("zone_ids") || d.HasChange("disk_type") {
641+
immutableArgs := []string{
642+
"zone_id", "period", "vpc_id",
643+
"subnet_id", "renew_flag", "kafka_version",
644+
"multi_zone_flag", "zone_ids", "disk_type",
645+
"specifications_type",
646+
}
628647

629-
return fmt.Errorf("parms like 'zone_id | period | vpc_id | subnet_id | renew_flag | " +
630-
"kafka_version | multi_zone_flag | zone_id | disk_type', do not support change now.")
648+
for _, v := range immutableArgs {
649+
if d.HasChange(v) {
650+
return fmt.Errorf("argument `%s` cannot be changed", v)
651+
}
631652
}
632653

633654
instanceId := d.Id()

website/docs/r/ckafka_instance.html.markdown

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,27 @@ description: |-
1111

1212
Use this resource to create ckafka instance.
1313

14-
~> **NOTE:** It only support create profession and prepaid ckafka instance.
14+
~> **NOTE:** It only support create prepaid ckafka instance.
1515

1616
## Example Usage
1717

1818
```hcl
1919
resource "tencentcloud_ckafka_instance" "foo" {
20-
band_width = 40
21-
disk_size = 500
22-
disk_type = "CLOUD_BASIC"
23-
period = 1
24-
instance_name = "ckafka-instance-tf-test"
25-
kafka_version = "1.1.1"
26-
msg_retention_time = 1300
27-
multi_zone_flag = true
28-
partition = 800
29-
public_network = 3
30-
renew_flag = 0
31-
subnet_id = "subnet-4vwihrzk"
32-
vpc_id = "vpc-82p1t1nv"
33-
zone_id = 100006
20+
band_width = 40
21+
disk_size = 500
22+
disk_type = "CLOUD_BASIC"
23+
period = 1
24+
instance_name = "ckafka-instance-tf-test"
25+
specifications_type = "profession"
26+
kafka_version = "1.1.1"
27+
msg_retention_time = 1300
28+
multi_zone_flag = true
29+
partition = 800
30+
public_network = 3
31+
renew_flag = 0
32+
subnet_id = "subnet-4vwihrzk"
33+
vpc_id = "vpc-82p1t1nv"
34+
zone_id = 100006
3435
zone_ids = [
3536
100006,
3637
100007,
@@ -70,6 +71,7 @@ The following arguments are supported:
7071
* `public_network` - (Optional, Int) Bandwidth of the public network.
7172
* `rebalance_time` - (Optional, Int) Modification of the rebalancing time after upgrade.
7273
* `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).
74+
* `specifications_type` - (Optional, String) Specifications type of instance. Allowed values are `standard`, `profession`. Default is `profession`.
7375
* `subnet_id` - (Optional, String) Subnet id, it will be basic network if not set.
7476
* `tag_set` - (Optional, Map) Tag set of instance.
7577
* `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.

0 commit comments

Comments
 (0)