4
4
"context"
5
5
"fmt"
6
6
"testing"
7
+ "time"
7
8
8
9
tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest"
9
10
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
@@ -17,7 +18,7 @@ import (
17
18
func TestAccTencentCloudCkafkaInstanceResource_prepaid (t * testing.T ) {
18
19
t .Parallel ()
19
20
resource .Test (t , resource.TestCase {
20
- PreCheck : func () { tcacctest .AccPreCheckCommon ( t , tcacctest . ACCOUNT_TYPE_PREPAY ) },
21
+ PreCheck : func () { tcacctest .AccPreCheck ( t ) },
21
22
Providers : tcacctest .AccProviders ,
22
23
CheckDestroy : testAccTencentCloudKafkaInstanceDestroy ,
23
24
Steps : []resource.TestStep {
@@ -27,6 +28,7 @@ func TestAccTencentCloudCkafkaInstanceResource_prepaid(t *testing.T) {
27
28
testAccCheckKafkaInstanceExists ("tencentcloud_ckafka_instance.kafka_instance" ),
28
29
resource .TestCheckResourceAttr ("tencentcloud_ckafka_instance.kafka_instance" , "instance_name" , "ckafka-instance-prepaid" ),
29
30
resource .TestCheckResourceAttr ("tencentcloud_ckafka_instance.kafka_instance" , "zone_id" , "100007" ),
31
+ resource .TestCheckResourceAttr ("tencentcloud_ckafka_instance.kafka_instance" , "charge_type" , "PREPAID" ),
30
32
resource .TestCheckResourceAttr ("tencentcloud_ckafka_instance.kafka_instance" , "period" , "1" ),
31
33
resource .TestCheckResourceAttr ("tencentcloud_ckafka_instance.kafka_instance" , "msg_retention_time" , "1300" ),
32
34
resource .TestCheckResourceAttr ("tencentcloud_ckafka_instance.kafka_instance" , "max_message_byte" , "1024" ),
@@ -44,6 +46,7 @@ func TestAccTencentCloudCkafkaInstanceResource_prepaid(t *testing.T) {
44
46
testAccCheckKafkaInstanceExists ("tencentcloud_ckafka_instance.kafka_instance" ),
45
47
resource .TestCheckResourceAttr ("tencentcloud_ckafka_instance.kafka_instance" , "instance_name" , "ckafka-instance-prepaid" ),
46
48
resource .TestCheckResourceAttr ("tencentcloud_ckafka_instance.kafka_instance" , "zone_id" , "100007" ),
49
+ resource .TestCheckResourceAttr ("tencentcloud_ckafka_instance.kafka_instance" , "charge_type" , "PREPAID" ),
47
50
resource .TestCheckResourceAttr ("tencentcloud_ckafka_instance.kafka_instance" , "period" , "1" ),
48
51
resource .TestCheckResourceAttr ("tencentcloud_ckafka_instance.kafka_instance" , "msg_retention_time" , "1200" ),
49
52
resource .TestCheckResourceAttr ("tencentcloud_ckafka_instance.kafka_instance" , "max_message_byte" , "1025" ),
@@ -54,10 +57,13 @@ func TestAccTencentCloudCkafkaInstanceResource_prepaid(t *testing.T) {
54
57
),
55
58
},
56
59
{
60
+ PreConfig : func () {
61
+ time .Sleep (2 * time .Minute )
62
+ },
57
63
ResourceName : "tencentcloud_ckafka_instance.kafka_instance" ,
58
64
ImportState : true ,
59
65
ImportStateVerify : true ,
60
- ImportStateVerifyIgnore : []string {"period" , "max_message_byte" , "charge_type" , " upgrade_strategy" },
66
+ ImportStateVerifyIgnore : []string {"period" , "max_message_byte" , "upgrade_strategy" },
61
67
},
62
68
},
63
69
})
@@ -66,7 +72,7 @@ func TestAccTencentCloudCkafkaInstanceResource_prepaid(t *testing.T) {
66
72
func TestAccTencentCloudCkafkaInstanceResource_postpaid (t * testing.T ) {
67
73
t .Parallel ()
68
74
resource .Test (t , resource.TestCase {
69
- PreCheck : func () { tcacctest .AccPreCheckCommon ( t , tcacctest . ACCOUNT_TYPE_PREPAY ) },
75
+ PreCheck : func () { tcacctest .AccPreCheck ( t ) },
70
76
Providers : tcacctest .AccProviders ,
71
77
CheckDestroy : testAccTencentCloudKafkaInstanceDestroy ,
72
78
Steps : []resource.TestStep {
@@ -107,7 +113,7 @@ func TestAccTencentCloudCkafkaInstanceResource_postpaid(t *testing.T) {
107
113
ResourceName : "tencentcloud_ckafka_instance.kafka_instance_postpaid" ,
108
114
ImportState : true ,
109
115
ImportStateVerify : true ,
110
- ImportStateVerifyIgnore : []string {"period" , "max_message_byte" , "charge_type" , " upgrade_strategy" },
116
+ ImportStateVerifyIgnore : []string {"period" , "max_message_byte" , "upgrade_strategy" },
111
117
},
112
118
},
113
119
})
@@ -116,7 +122,7 @@ func TestAccTencentCloudCkafkaInstanceResource_postpaid(t *testing.T) {
116
122
func TestAccTencentCloudCkafkaInstanceResource_maz (t * testing.T ) {
117
123
t .Parallel ()
118
124
resource .Test (t , resource.TestCase {
119
- PreCheck : func () { tcacctest .AccPreCheckCommon ( t , tcacctest . ACCOUNT_TYPE_PREPAY ) },
125
+ PreCheck : func () { tcacctest .AccPreCheck ( t ) },
120
126
Providers : tcacctest .AccProviders ,
121
127
CheckDestroy : testAccTencentCloudKafkaInstanceDestroy ,
122
128
Steps : []resource.TestStep {
@@ -130,10 +136,13 @@ func TestAccTencentCloudCkafkaInstanceResource_maz(t *testing.T) {
130
136
),
131
137
},
132
138
{
139
+ PreConfig : func () {
140
+ time .Sleep (2 * time .Minute )
141
+ },
133
142
ResourceName : "tencentcloud_ckafka_instance.kafka_instance" ,
134
143
ImportState : true ,
135
144
ImportStateVerify : true ,
136
- ImportStateVerifyIgnore : []string {"period" , "max_message_byte" , "charge_type" , " upgrade_strategy" },
145
+ ImportStateVerifyIgnore : []string {"period" , "max_message_byte" , "upgrade_strategy" },
137
146
},
138
147
},
139
148
})
@@ -142,7 +151,7 @@ func TestAccTencentCloudCkafkaInstanceResource_maz(t *testing.T) {
142
151
func TestAccTencentCloudCkafkaInstanceResource_type (t * testing.T ) {
143
152
t .Parallel ()
144
153
resource .Test (t , resource.TestCase {
145
- PreCheck : func () { tcacctest .AccPreCheckCommon ( t , tcacctest . ACCOUNT_TYPE_PREPAY ) },
154
+ PreCheck : func () { tcacctest .AccPreCheck ( t ) },
146
155
Providers : tcacctest .AccProviders ,
147
156
CheckDestroy : testAccTencentCloudKafkaInstanceDestroy ,
148
157
Steps : []resource.TestStep {
@@ -151,15 +160,17 @@ func TestAccTencentCloudCkafkaInstanceResource_type(t *testing.T) {
151
160
Check : resource .ComposeTestCheckFunc (
152
161
testAccCheckKafkaInstanceExists ("tencentcloud_ckafka_instance.kafka_instance" ),
153
162
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" ),
156
164
),
157
165
},
158
166
{
167
+ PreConfig : func () {
168
+ time .Sleep (2 * time .Minute )
169
+ },
159
170
ResourceName : "tencentcloud_ckafka_instance.kafka_instance" ,
160
171
ImportState : true ,
161
172
ImportStateVerify : true ,
162
- ImportStateVerifyIgnore : []string {"period" , "max_message_byte" , "charge_type" , " upgrade_strategy" },
173
+ ImportStateVerifyIgnore : []string {"period" , "max_message_byte" , "upgrade_strategy" },
163
174
},
164
175
},
165
176
})
@@ -173,7 +184,7 @@ func testAccTencentCloudKafkaInstanceDestroy(s *terraform.State) error {
173
184
if r .Type != "tencentcloud_ckafka_instance" {
174
185
continue
175
186
}
176
- _ , has , error := ckafkcService .DescribeInstanceById (ctx , r .Primary .ID )
187
+ _ , has , error := ckafkcService .DescribeCkafkaById (ctx , r .Primary .ID )
177
188
if error != nil {
178
189
return error
179
190
}
@@ -219,12 +230,25 @@ func testAccCheckKafkaInstanceExists(n string) resource.TestCheckFunc {
219
230
}
220
231
221
232
const 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
+
222
246
resource "tencentcloud_ckafka_instance" "kafka_instance" {
223
247
instance_name = "ckafka-instance-prepaid"
224
248
zone_id = 100007
225
249
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
228
252
msg_retention_time = 1300
229
253
max_message_byte = 1024
230
254
renew_flag = 0
@@ -247,13 +271,26 @@ resource "tencentcloud_ckafka_instance" "kafka_instance" {
247
271
}
248
272
`
249
273
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
+
251
288
resource "tencentcloud_ckafka_instance" "kafka_instance" {
252
289
instance_name = "ckafka-instance-prepaid"
253
290
zone_id = 100007
254
291
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
257
294
msg_retention_time = 1200
258
295
max_message_byte = 1025
259
296
renew_flag = 0
@@ -280,12 +317,25 @@ resource "tencentcloud_ckafka_instance" "kafka_instance" {
280
317
}
281
318
`
282
319
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
+
284
334
resource "tencentcloud_ckafka_instance" "kafka_instance_postpaid" {
285
335
instance_name = "ckafka-instance-postpaid"
286
336
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
289
339
msg_retention_time = 1300
290
340
kafka_version = "1.1.1"
291
341
disk_size = 500
@@ -318,12 +368,25 @@ resource "tencentcloud_ckafka_topic" "foo" {
318
368
}
319
369
`
320
370
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
+
322
385
resource "tencentcloud_ckafka_instance" "kafka_instance_postpaid" {
323
386
instance_name = "ckafka-instance-postpaid"
324
387
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
327
390
msg_retention_time = 1200
328
391
kafka_version = "1.1.1"
329
392
disk_type = "CLOUD_BASIC"
@@ -359,12 +422,25 @@ resource "tencentcloud_ckafka_topic" "foo" {
359
422
}
360
423
`
361
424
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
+
363
439
resource "tencentcloud_ckafka_instance" "kafka_instance_postpaid" {
364
440
instance_name = "ckafka-instance-postpaid"
365
441
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
368
444
msg_retention_time = 1200
369
445
kafka_version = "1.1.1"
370
446
disk_type = "CLOUD_BASIC"
@@ -400,15 +476,28 @@ resource "tencentcloud_ckafka_topic" "foo" {
400
476
}
401
477
`
402
478
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
+
404
493
resource "tencentcloud_ckafka_instance" "kafka_instance" {
405
494
instance_name = "ckafka-instance-maz-tf-test"
406
495
zone_id = 100007
407
496
multi_zone_flag = true
408
497
zone_ids = [100007, 100006]
409
498
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
412
501
msg_retention_time = 1300
413
502
renew_flag = 0
414
503
kafka_version = "1.1.1"
@@ -430,13 +519,13 @@ resource "tencentcloud_ckafka_instance" "kafka_instance" {
430
519
431
520
const testAccKafkaInstanceType = `
432
521
resource "tencentcloud_vpc" "vpc" {
433
- name = "tmp "
522
+ name = "kafka-type-vpc "
434
523
cidr_block = "10.0.0.0/16"
435
524
}
436
525
437
526
resource "tencentcloud_subnet" "subnet" {
438
527
vpc_id = tencentcloud_vpc.vpc.id
439
- name = "subnet-example "
528
+ name = "kafka-type-subnet "
440
529
cidr_block = "10.0.0.0/16"
441
530
availability_zone = "ap-guangzhou-7"
442
531
}
@@ -448,11 +537,11 @@ resource "tencentcloud_ckafka_instance" "kafka_instance" {
448
537
subnet_id = tencentcloud_subnet.subnet.id
449
538
msg_retention_time = 1300
450
539
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
454
542
disk_type = "CLOUD_BASIC"
455
- band_width = 100
543
+ band_width = 20
544
+ partition = 400
456
545
charge_type = "POSTPAID_BY_HOUR"
457
546
458
547
config {
0 commit comments