|
1 | 1 | /* |
2 | 2 | Use this resource to create ckafka instance. |
3 | 3 |
|
4 | | -~> **NOTE:** It only support create profession and prepaid ckafka instance. |
| 4 | +~> **NOTE:** It only support create prepaid ckafka instance. |
5 | 5 |
|
6 | 6 | Example Usage |
7 | 7 |
|
8 | 8 | ```hcl |
9 | 9 | 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 = [ |
25 | 26 | 100006, |
26 | 27 | 100007, |
27 | 28 | ] |
@@ -95,6 +96,13 @@ func resourceTencentCloudCkafkaInstance() *schema.Resource { |
95 | 96 | return zoneIds.Contains(zoneId) |
96 | 97 | }, |
97 | 98 | }, |
| 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 | + }, |
98 | 106 | "period": { |
99 | 107 | Type: schema.TypeInt, |
100 | 108 | Optional: true, |
@@ -307,9 +315,11 @@ func resourceTencentCloudCkafkaInstanceCreate(d *schema.ResourceData, meta inter |
307 | 315 |
|
308 | 316 | period := int64(d.Get("period").(int)) |
309 | 317 | 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 | + } |
313 | 323 |
|
314 | 324 | if v, ok := d.GetOk("vpc_id"); ok { |
315 | 325 | vpcId := v.(string) |
@@ -539,8 +549,13 @@ func resourceTencentCloudCkafkaInstanceRead(d *schema.ResourceData, meta interfa |
539 | 549 | _ = d.Set("vport", info.Vport) |
540 | 550 | _ = d.Set("band_width", *bandWidth/8) |
541 | 551 | _ = 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 | + } |
542 | 557 |
|
543 | | - if len(info.ZoneIds) > 0 { |
| 558 | + if len(info.ZoneIds) > 1 { |
544 | 559 | _ = d.Set("multi_zone_flag", true) |
545 | 560 | ids := helper.Int64sInterfaces(info.ZoneIds) |
546 | 561 | idSet := schema.NewSet(func(i interface{}) int { |
@@ -623,11 +638,17 @@ func resourceTencentCloudCkafkaInstanceUpdate(d *schema.ResourceData, meta inter |
623 | 638 | client: meta.(*TencentCloudClient).apiV3Conn, |
624 | 639 | } |
625 | 640 |
|
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 | + } |
628 | 647 |
|
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 | + } |
631 | 652 | } |
632 | 653 |
|
633 | 654 | instanceId := d.Id() |
|
0 commit comments