44 "context"
55 "fmt"
66 "testing"
7+ "time"
78
89 tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest"
910 tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
@@ -17,7 +18,7 @@ import (
1718func TestAccTencentCloudCkafkaInstanceResource_prepaid (t * testing.T ) {
1819 t .Parallel ()
1920 resource .Test (t , resource.TestCase {
20- PreCheck : func () { tcacctest .AccPreCheckCommon ( t , tcacctest . ACCOUNT_TYPE_PREPAY ) },
21+ PreCheck : func () { tcacctest .AccPreCheck ( t ) },
2122 Providers : tcacctest .AccProviders ,
2223 CheckDestroy : testAccTencentCloudKafkaInstanceDestroy ,
2324 Steps : []resource.TestStep {
@@ -27,6 +28,7 @@ func TestAccTencentCloudCkafkaInstanceResource_prepaid(t *testing.T) {
2728 testAccCheckKafkaInstanceExists ("tencentcloud_ckafka_instance.kafka_instance" ),
2829 resource .TestCheckResourceAttr ("tencentcloud_ckafka_instance.kafka_instance" , "instance_name" , "ckafka-instance-prepaid" ),
2930 resource .TestCheckResourceAttr ("tencentcloud_ckafka_instance.kafka_instance" , "zone_id" , "100007" ),
31+ resource .TestCheckResourceAttr ("tencentcloud_ckafka_instance.kafka_instance" , "charge_type" , "PREPAID" ),
3032 resource .TestCheckResourceAttr ("tencentcloud_ckafka_instance.kafka_instance" , "period" , "1" ),
3133 resource .TestCheckResourceAttr ("tencentcloud_ckafka_instance.kafka_instance" , "msg_retention_time" , "1300" ),
3234 resource .TestCheckResourceAttr ("tencentcloud_ckafka_instance.kafka_instance" , "max_message_byte" , "1024" ),
@@ -44,6 +46,7 @@ func TestAccTencentCloudCkafkaInstanceResource_prepaid(t *testing.T) {
4446 testAccCheckKafkaInstanceExists ("tencentcloud_ckafka_instance.kafka_instance" ),
4547 resource .TestCheckResourceAttr ("tencentcloud_ckafka_instance.kafka_instance" , "instance_name" , "ckafka-instance-prepaid" ),
4648 resource .TestCheckResourceAttr ("tencentcloud_ckafka_instance.kafka_instance" , "zone_id" , "100007" ),
49+ resource .TestCheckResourceAttr ("tencentcloud_ckafka_instance.kafka_instance" , "charge_type" , "PREPAID" ),
4750 resource .TestCheckResourceAttr ("tencentcloud_ckafka_instance.kafka_instance" , "period" , "1" ),
4851 resource .TestCheckResourceAttr ("tencentcloud_ckafka_instance.kafka_instance" , "msg_retention_time" , "1200" ),
4952 resource .TestCheckResourceAttr ("tencentcloud_ckafka_instance.kafka_instance" , "max_message_byte" , "1025" ),
@@ -54,10 +57,13 @@ func TestAccTencentCloudCkafkaInstanceResource_prepaid(t *testing.T) {
5457 ),
5558 },
5659 {
60+ PreConfig : func () {
61+ time .Sleep (2 * time .Minute )
62+ },
5763 ResourceName : "tencentcloud_ckafka_instance.kafka_instance" ,
5864 ImportState : true ,
5965 ImportStateVerify : true ,
60- ImportStateVerifyIgnore : []string {"period" , "max_message_byte" , "charge_type" , " upgrade_strategy" },
66+ ImportStateVerifyIgnore : []string {"period" , "max_message_byte" , "upgrade_strategy" },
6167 },
6268 },
6369 })
@@ -66,7 +72,7 @@ func TestAccTencentCloudCkafkaInstanceResource_prepaid(t *testing.T) {
6672func TestAccTencentCloudCkafkaInstanceResource_postpaid (t * testing.T ) {
6773 t .Parallel ()
6874 resource .Test (t , resource.TestCase {
69- PreCheck : func () { tcacctest .AccPreCheckCommon ( t , tcacctest . ACCOUNT_TYPE_PREPAY ) },
75+ PreCheck : func () { tcacctest .AccPreCheck ( t ) },
7076 Providers : tcacctest .AccProviders ,
7177 CheckDestroy : testAccTencentCloudKafkaInstanceDestroy ,
7278 Steps : []resource.TestStep {
@@ -107,7 +113,7 @@ func TestAccTencentCloudCkafkaInstanceResource_postpaid(t *testing.T) {
107113 ResourceName : "tencentcloud_ckafka_instance.kafka_instance_postpaid" ,
108114 ImportState : true ,
109115 ImportStateVerify : true ,
110- ImportStateVerifyIgnore : []string {"period" , "max_message_byte" , "charge_type" , " upgrade_strategy" },
116+ ImportStateVerifyIgnore : []string {"period" , "max_message_byte" , "upgrade_strategy" },
111117 },
112118 },
113119 })
@@ -116,7 +122,7 @@ func TestAccTencentCloudCkafkaInstanceResource_postpaid(t *testing.T) {
116122func TestAccTencentCloudCkafkaInstanceResource_maz (t * testing.T ) {
117123 t .Parallel ()
118124 resource .Test (t , resource.TestCase {
119- PreCheck : func () { tcacctest .AccPreCheckCommon ( t , tcacctest . ACCOUNT_TYPE_PREPAY ) },
125+ PreCheck : func () { tcacctest .AccPreCheck ( t ) },
120126 Providers : tcacctest .AccProviders ,
121127 CheckDestroy : testAccTencentCloudKafkaInstanceDestroy ,
122128 Steps : []resource.TestStep {
@@ -130,10 +136,13 @@ func TestAccTencentCloudCkafkaInstanceResource_maz(t *testing.T) {
130136 ),
131137 },
132138 {
139+ PreConfig : func () {
140+ time .Sleep (2 * time .Minute )
141+ },
133142 ResourceName : "tencentcloud_ckafka_instance.kafka_instance" ,
134143 ImportState : true ,
135144 ImportStateVerify : true ,
136- ImportStateVerifyIgnore : []string {"period" , "max_message_byte" , "charge_type" , " upgrade_strategy" },
145+ ImportStateVerifyIgnore : []string {"period" , "max_message_byte" , "upgrade_strategy" },
137146 },
138147 },
139148 })
@@ -142,7 +151,7 @@ func TestAccTencentCloudCkafkaInstanceResource_maz(t *testing.T) {
142151func TestAccTencentCloudCkafkaInstanceResource_type (t * testing.T ) {
143152 t .Parallel ()
144153 resource .Test (t , resource.TestCase {
145- PreCheck : func () { tcacctest .AccPreCheckCommon ( t , tcacctest . ACCOUNT_TYPE_PREPAY ) },
154+ PreCheck : func () { tcacctest .AccPreCheck ( t ) },
146155 Providers : tcacctest .AccProviders ,
147156 CheckDestroy : testAccTencentCloudKafkaInstanceDestroy ,
148157 Steps : []resource.TestStep {
@@ -151,15 +160,17 @@ func TestAccTencentCloudCkafkaInstanceResource_type(t *testing.T) {
151160 Check : resource .ComposeTestCheckFunc (
152161 testAccCheckKafkaInstanceExists ("tencentcloud_ckafka_instance.kafka_instance" ),
153162 resource .TestCheckResourceAttr ("tencentcloud_ckafka_instance.kafka_instance" , "instance_name" , "ckafka-instance-type-tf-test" ),
154- resource .TestCheckResourceAttr ("tencentcloud_ckafka_instance.kafka_instance" , "specifications_type" , "standard" ),
155- resource .TestCheckResourceAttr ("tencentcloud_ckafka_instance.kafka_instance" , "instance_type" , "2" ),
163+ resource .TestCheckResourceAttr ("tencentcloud_ckafka_instance.kafka_instance" , "specifications_type" , "profession" ),
156164 ),
157165 },
158166 {
167+ PreConfig : func () {
168+ time .Sleep (2 * time .Minute )
169+ },
159170 ResourceName : "tencentcloud_ckafka_instance.kafka_instance" ,
160171 ImportState : true ,
161172 ImportStateVerify : true ,
162- ImportStateVerifyIgnore : []string {"period" , "max_message_byte" , "charge_type" , " upgrade_strategy" },
173+ ImportStateVerifyIgnore : []string {"period" , "max_message_byte" , "upgrade_strategy" },
163174 },
164175 },
165176 })
@@ -173,7 +184,7 @@ func testAccTencentCloudKafkaInstanceDestroy(s *terraform.State) error {
173184 if r .Type != "tencentcloud_ckafka_instance" {
174185 continue
175186 }
176- _ , has , error := ckafkcService .DescribeInstanceById (ctx , r .Primary .ID )
187+ _ , has , error := ckafkcService .DescribeCkafkaById (ctx , r .Primary .ID )
177188 if error != nil {
178189 return error
179190 }
@@ -219,12 +230,25 @@ func testAccCheckKafkaInstanceExists(n string) resource.TestCheckFunc {
219230}
220231
221232const testAccKafkaInstance = tcacctest .DefaultKafkaVariable + `
233+ resource "tencentcloud_vpc" "kafka_vpc" {
234+ name = "kafka-vpc"
235+ cidr_block = "10.0.0.0/16"
236+ }
237+
238+ resource "tencentcloud_subnet" "kafka_subnet" {
239+ vpc_id = tencentcloud_vpc.kafka_vpc.id
240+ name = "kafka-subnet"
241+ cidr_block = "10.0.0.0/16"
242+ availability_zone = "ap-guangzhou-7"
243+ is_multicast = false
244+ }
245+
222246resource "tencentcloud_ckafka_instance" "kafka_instance" {
223247 instance_name = "ckafka-instance-prepaid"
224248 zone_id = 100007
225249 period = 1
226- vpc_id = var.vpc_id
227- subnet_id = var.subnet_id
250+ vpc_id = tencentcloud_vpc.kafka_vpc.id
251+ subnet_id = tencentcloud_subnet.kafka_subnet.id
228252 msg_retention_time = 1300
229253 max_message_byte = 1024
230254 renew_flag = 0
@@ -247,13 +271,26 @@ resource "tencentcloud_ckafka_instance" "kafka_instance" {
247271}
248272`
249273
250- const testAccKafkaInstanceUpdate = tcacctest .DefaultKafkaVariable + `
274+ const testAccKafkaInstanceUpdate = `
275+ resource "tencentcloud_vpc" "kafka_vpc" {
276+ name = "kafka-vpc"
277+ cidr_block = "10.0.0.0/16"
278+ }
279+
280+ resource "tencentcloud_subnet" "kafka_subnet" {
281+ vpc_id = tencentcloud_vpc.kafka_vpc.id
282+ name = "kafka-subnet"
283+ cidr_block = "10.0.0.0/16"
284+ availability_zone = "ap-guangzhou-7"
285+ is_multicast = false
286+ }
287+
251288resource "tencentcloud_ckafka_instance" "kafka_instance" {
252289 instance_name = "ckafka-instance-prepaid"
253290 zone_id = 100007
254291 period = 1
255- vpc_id = var.vpc_id
256- subnet_id = var.subnet_id
292+ vpc_id = tencentcloud_vpc.kafka_vpc.id
293+ subnet_id = tencentcloud_subnet.kafka_subnet.id
257294 msg_retention_time = 1200
258295 max_message_byte = 1025
259296 renew_flag = 0
@@ -280,12 +317,25 @@ resource "tencentcloud_ckafka_instance" "kafka_instance" {
280317}
281318`
282319
283- const testAccKafkaInstancePostpaid = tcacctest .DefaultKafkaVariable + `
320+ const testAccKafkaInstancePostpaid = `
321+ resource "tencentcloud_vpc" "kafka_vpc" {
322+ name = "postpaid-kafka-vpc"
323+ cidr_block = "10.0.0.0/16"
324+ }
325+
326+ resource "tencentcloud_subnet" "kafka_subnet" {
327+ vpc_id = tencentcloud_vpc.kafka_vpc.id
328+ name = "postpaid-kafka-subnet"
329+ cidr_block = "10.0.0.0/16"
330+ availability_zone = "ap-guangzhou-7"
331+ is_multicast = false
332+ }
333+
284334resource "tencentcloud_ckafka_instance" "kafka_instance_postpaid" {
285335 instance_name = "ckafka-instance-postpaid"
286336 zone_id = 100007
287- vpc_id = var.vpc_id
288- subnet_id = var.subnet_id
337+ vpc_id = tencentcloud_vpc.kafka_vpc.id
338+ subnet_id = tencentcloud_subnet.kafka_subnet.id
289339 msg_retention_time = 1300
290340 kafka_version = "1.1.1"
291341 disk_size = 500
@@ -318,12 +368,25 @@ resource "tencentcloud_ckafka_topic" "foo" {
318368}
319369`
320370
321- const testAccKafkaInstanceUpdatePostpaid = tcacctest .DefaultKafkaVariable + `
371+ const testAccKafkaInstanceUpdatePostpaid = `
372+ resource "tencentcloud_vpc" "kafka_vpc" {
373+ name = "postpaid-kafka-vpc"
374+ cidr_block = "10.0.0.0/16"
375+ }
376+
377+ resource "tencentcloud_subnet" "kafka_subnet" {
378+ vpc_id = tencentcloud_vpc.kafka_vpc.id
379+ name = "postpaid-kafka-subnet"
380+ cidr_block = "10.0.0.0/16"
381+ availability_zone = "ap-guangzhou-7"
382+ is_multicast = false
383+ }
384+
322385resource "tencentcloud_ckafka_instance" "kafka_instance_postpaid" {
323386 instance_name = "ckafka-instance-postpaid"
324387 zone_id = 100007
325- vpc_id = var.vpc_id
326- subnet_id = var.subnet_id
388+ vpc_id = tencentcloud_vpc.kafka_vpc.id
389+ subnet_id = tencentcloud_subnet.kafka_subnet.id
327390 msg_retention_time = 1200
328391 kafka_version = "1.1.1"
329392 disk_type = "CLOUD_BASIC"
@@ -359,12 +422,25 @@ resource "tencentcloud_ckafka_topic" "foo" {
359422}
360423`
361424
362- const testAccKafkaInstanceUpdatePostpaidDiskSize = tcacctest .DefaultKafkaVariable + `
425+ const testAccKafkaInstanceUpdatePostpaidDiskSize = `
426+ resource "tencentcloud_vpc" "kafka_vpc" {
427+ name = "postpaid-kafka-vpc"
428+ cidr_block = "10.0.0.0/16"
429+ }
430+
431+ resource "tencentcloud_subnet" "kafka_subnet" {
432+ vpc_id = tencentcloud_vpc.kafka_vpc.id
433+ name = "postpaid-kafka-subnet"
434+ cidr_block = "10.0.0.0/16"
435+ availability_zone = "ap-guangzhou-7"
436+ is_multicast = false
437+ }
438+
363439resource "tencentcloud_ckafka_instance" "kafka_instance_postpaid" {
364440 instance_name = "ckafka-instance-postpaid"
365441 zone_id = 100007
366- vpc_id = var.vpc_id
367- subnet_id = var.subnet_id
442+ vpc_id = tencentcloud_vpc.kafka_vpc.id
443+ subnet_id = tencentcloud_subnet.kafka_subnet.id
368444 msg_retention_time = 1200
369445 kafka_version = "1.1.1"
370446 disk_type = "CLOUD_BASIC"
@@ -400,15 +476,28 @@ resource "tencentcloud_ckafka_topic" "foo" {
400476}
401477`
402478
403- const testAccKafkaInstanceMAZ = tcacctest .DefaultKafkaVariable + `
479+ const testAccKafkaInstanceMAZ = `
480+ resource "tencentcloud_vpc" "kafka_vpc" {
481+ name = "maz-kafka-vpc"
482+ cidr_block = "10.0.0.0/16"
483+ }
484+
485+ resource "tencentcloud_subnet" "kafka_subnet" {
486+ vpc_id = tencentcloud_vpc.kafka_vpc.id
487+ name = "maz-kafka-subnet"
488+ cidr_block = "10.0.0.0/16"
489+ availability_zone = "ap-guangzhou-7"
490+ is_multicast = false
491+ }
492+
404493resource "tencentcloud_ckafka_instance" "kafka_instance" {
405494 instance_name = "ckafka-instance-maz-tf-test"
406495 zone_id = 100007
407496 multi_zone_flag = true
408497 zone_ids = [100007, 100006]
409498 period = 1
410- vpc_id = var.vpc_id
411- subnet_id = var.subnet_id
499+ vpc_id = tencentcloud_vpc.kafka_vpc.id
500+ subnet_id = tencentcloud_subnet.kafka_subnet.id
412501 msg_retention_time = 1300
413502 renew_flag = 0
414503 kafka_version = "1.1.1"
@@ -430,13 +519,13 @@ resource "tencentcloud_ckafka_instance" "kafka_instance" {
430519
431520const testAccKafkaInstanceType = `
432521resource "tencentcloud_vpc" "vpc" {
433- name = "tmp "
522+ name = "kafka-type-vpc "
434523 cidr_block = "10.0.0.0/16"
435524}
436525
437526resource "tencentcloud_subnet" "subnet" {
438527 vpc_id = tencentcloud_vpc.vpc.id
439- name = "subnet-example "
528+ name = "kafka-type-subnet "
440529 cidr_block = "10.0.0.0/16"
441530 availability_zone = "ap-guangzhou-7"
442531}
@@ -448,11 +537,11 @@ resource "tencentcloud_ckafka_instance" "kafka_instance" {
448537 subnet_id = tencentcloud_subnet.subnet.id
449538 msg_retention_time = 1300
450539 kafka_version = "1.1.1"
451- specifications_type = "standard"
452- instance_type = 2
453- disk_size = 1000
540+ specifications_type = "profession"
541+ disk_size = 200
454542 disk_type = "CLOUD_BASIC"
455- band_width = 100
543+ band_width = 20
544+ partition = 400
456545 charge_type = "POSTPAID_BY_HOUR"
457546
458547 config {
0 commit comments