@@ -403,9 +403,6 @@ func TestAccTencentCloudInstanceResource_WithSecurityGroup(t *testing.T) {
403
403
t .Parallel ()
404
404
405
405
instanceId := "tencentcloud_instance.foo"
406
- securitygroupId := "tencentcloud_security_group.foo"
407
- securitygroupRuleFooId := "tencentcloud_security_group_rule.foo"
408
- securitygroupRuleBarId := "tencentcloud_security_group_rule.bar"
409
406
410
407
resource .Test (t , resource.TestCase {
411
408
PreCheck : func () { tcacctest .AccPreCheck (t ) },
@@ -414,34 +411,21 @@ func TestAccTencentCloudInstanceResource_WithSecurityGroup(t *testing.T) {
414
411
CheckDestroy : testAccCheckInstanceDestroy ,
415
412
Steps : []resource.TestStep {
416
413
{
417
- Config : testAccTencentCloudInstanceWithSecurityGroup (`[tencentcloud_security_group.foo.id ]` ),
414
+ Config : testAccTencentCloudInstanceWithSecurityGroup (`["sg-cm7fbbf3" ]` ),
418
415
Check : resource .ComposeTestCheckFunc (
419
416
tcacctest .AccCheckTencentCloudDataSourceID (instanceId ),
420
417
testAccCheckTencentCloudInstanceExists (instanceId ),
421
418
resource .TestCheckResourceAttr (instanceId , "instance_status" , "RUNNING" ),
422
419
resource .TestCheckResourceAttr (instanceId , "security_groups.#" , "1" ),
423
- resource .TestCheckResourceAttrSet (securitygroupId , "id" ),
424
- resource .TestCheckResourceAttr (securitygroupRuleFooId , "type" , "ingress" ),
425
- resource .TestCheckResourceAttr (securitygroupRuleFooId , "port_range" , "80,8080" ),
426
- resource .TestCheckResourceAttr (securitygroupRuleBarId , "type" , "ingress" ),
427
- resource .TestCheckResourceAttr (securitygroupRuleBarId , "port_range" , "3000" ),
428
420
),
429
421
},
430
422
{
431
423
Config : testAccTencentCloudInstanceWithSecurityGroup (`[
432
- tencentcloud_security_group.foo.id ,
433
- tencentcloud_security_group.bar.id
424
+ "sg-cm7fbbf3" ,
425
+ "sg-kensue7b"
434
426
]` ),
435
427
Check : resource .ComposeTestCheckFunc (
436
- tcacctest .AccCheckTencentCloudDataSourceID (instanceId ),
437
- testAccCheckTencentCloudInstanceExists (instanceId ),
438
- resource .TestCheckResourceAttr (instanceId , "instance_status" , "RUNNING" ),
439
428
resource .TestCheckResourceAttr (instanceId , "security_groups.#" , "2" ),
440
- resource .TestCheckResourceAttrSet (securitygroupId , "id" ),
441
- resource .TestCheckResourceAttr (securitygroupRuleFooId , "type" , "ingress" ),
442
- resource .TestCheckResourceAttr (securitygroupRuleFooId , "port_range" , "80,8080" ),
443
- resource .TestCheckResourceAttr (securitygroupRuleBarId , "type" , "ingress" ),
444
- resource .TestCheckResourceAttr (securitygroupRuleBarId , "port_range" , "3000" ),
445
429
),
446
430
},
447
431
},
@@ -451,11 +435,7 @@ func TestAccTencentCloudInstanceResource_WithSecurityGroup(t *testing.T) {
451
435
func TestAccTencentCloudInstanceResource_WithOrderlySecurityGroup (t * testing.T ) {
452
436
t .Parallel ()
453
437
454
- var sgId1 , sgId2 , sgId3 string
455
438
instanceId := "tencentcloud_instance.cvm_with_orderly_sg"
456
- orderlySecurityGroupId1 := "tencentcloud_security_group.orderly_security_group1"
457
- orderlySecurityGroupId2 := "tencentcloud_security_group.orderly_security_group2"
458
- orderlySecurityGroupId3 := "tencentcloud_security_group.orderly_security_group3"
459
439
460
440
resource .Test (t , resource.TestCase {
461
441
PreCheck : func () { tcacctest .AccPreCheck (t ) },
@@ -464,38 +444,13 @@ func TestAccTencentCloudInstanceResource_WithOrderlySecurityGroup(t *testing.T)
464
444
CheckDestroy : testAccCheckInstanceDestroy ,
465
445
Steps : []resource.TestStep {
466
446
{
467
- Config : testAccTencentCloudInstanceOrderlySecurityGroups (`[
468
- tencentcloud_security_group.orderly_security_group1.id,
469
- tencentcloud_security_group.orderly_security_group2.id,
470
- tencentcloud_security_group.orderly_security_group3.id
471
- ]` ),
472
- Check : resource .ComposeTestCheckFunc (
473
- testAccCheckTencentCloudInstanceExists (instanceId ),
474
- testAccCheckSecurityGroupExists (orderlySecurityGroupId1 , & sgId1 ),
475
- testAccCheckSecurityGroupExists (orderlySecurityGroupId2 , & sgId2 ),
476
- testAccCheckSecurityGroupExists (orderlySecurityGroupId3 , & sgId3 ),
477
-
478
- resource .TestCheckResourceAttrPtr (instanceId , "orderly_security_groups.0" , & sgId1 ),
479
- resource .TestCheckResourceAttrPtr (instanceId , "orderly_security_groups.1" , & sgId2 ),
480
- resource .TestCheckResourceAttrPtr (instanceId , "orderly_security_groups.2" , & sgId3 ),
481
- ),
482
- },
483
-
484
- {
485
- Config : testAccTencentCloudInstanceOrderlySecurityGroups (`[
486
- tencentcloud_security_group.orderly_security_group3.id,
487
- tencentcloud_security_group.orderly_security_group2.id,
488
- tencentcloud_security_group.orderly_security_group1.id
489
- ]` ),
447
+ Config : testAccTencentCloudInstanceOrderlySecurityGroups ,
490
448
Check : resource .ComposeTestCheckFunc (
491
449
testAccCheckTencentCloudInstanceExists (instanceId ),
492
- testAccCheckSecurityGroupExists (orderlySecurityGroupId1 , & sgId1 ),
493
- testAccCheckSecurityGroupExists (orderlySecurityGroupId2 , & sgId2 ),
494
- testAccCheckSecurityGroupExists (orderlySecurityGroupId3 , & sgId3 ),
495
450
496
- resource .TestCheckResourceAttrPtr (instanceId , "orderly_security_groups.0" , & sgId3 ),
497
- resource .TestCheckResourceAttrPtr (instanceId , "orderly_security_groups.1" , & sgId2 ),
498
- resource .TestCheckResourceAttrPtr (instanceId , "orderly_security_groups.2" , & sgId1 ),
451
+ resource .TestCheckResourceAttr (instanceId , "orderly_security_groups.0" , "sg-cm7fbbf3" ),
452
+ resource .TestCheckResourceAttr (instanceId , "orderly_security_groups.1" , "sg-kensue7b" ),
453
+ resource .TestCheckResourceAttr (instanceId , "orderly_security_groups.2" , "sg-05f7wnhn" ),
499
454
),
500
455
},
501
456
},
@@ -1337,34 +1292,6 @@ resource "tencentcloud_instance" "foo" {
1337
1292
func testAccTencentCloudInstanceWithSecurityGroup (ids string ) string {
1338
1293
return fmt .Sprintf (
1339
1294
tcacctest .DefaultInstanceVariable + `
1340
- resource "tencentcloud_security_group" "foo" {
1341
- name = var.instance_name
1342
- description = var.instance_name
1343
- }
1344
-
1345
- resource "tencentcloud_security_group_rule" "foo" {
1346
- security_group_id = tencentcloud_security_group.foo.id
1347
- type = "ingress"
1348
- cidr_ip = "0.0.0.0/0"
1349
- ip_protocol = "tcp"
1350
- port_range = "80,8080"
1351
- policy = "accept"
1352
- }
1353
-
1354
- resource "tencentcloud_security_group" "bar" {
1355
- name = var.instance_name
1356
- description = var.instance_name
1357
- }
1358
-
1359
- resource "tencentcloud_security_group_rule" "bar" {
1360
- security_group_id = tencentcloud_security_group.bar.id
1361
- type = "ingress"
1362
- cidr_ip = "0.0.0.0/0"
1363
- ip_protocol = "tcp"
1364
- port_range = "3000"
1365
- policy = "accept"
1366
- }
1367
-
1368
1295
resource "tencentcloud_instance" "foo" {
1369
1296
instance_name = var.instance_name
1370
1297
availability_zone = var.availability_cvm_zone
@@ -1429,34 +1356,13 @@ resource "tencentcloud_instance" "foo" {
1429
1356
}
1430
1357
`
1431
1358
1432
- func testAccTencentCloudInstanceOrderlySecurityGroups (sgs string ) string {
1433
-
1434
- return fmt .Sprintf (tcacctest .DefaultInstanceVariable + `
1435
- resource "tencentcloud_security_group" "orderly_security_group1" {
1436
- name = "test-cvm-orderly-sg1"
1437
- description = "test-cvm-orderly-sg1"
1438
- }
1439
-
1440
- resource "tencentcloud_security_group" "orderly_security_group2" {
1441
- name = "test-cvm-orderly-sg2"
1442
- description = "test-cvm-orderly-sg2"
1443
- }
1444
-
1445
- resource "tencentcloud_security_group" "orderly_security_group3" {
1446
- name = "test-cvm-orderly-sg3"
1447
- description = "test-cvm-orderly-sg3"
1448
- }
1449
-
1359
+ const testAccTencentCloudInstanceOrderlySecurityGroups = tcacctest .DefaultInstanceVariable + `
1450
1360
resource "tencentcloud_instance" "cvm_with_orderly_sg" {
1451
1361
instance_name = "test-orderly-sg-cvm"
1452
1362
availability_zone = var.availability_cvm_zone
1453
1363
image_id = data.tencentcloud_images.default.images.0.image_id
1454
1364
instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type
1455
1365
system_disk_type = "CLOUD_PREMIUM"
1456
- orderly_security_groups = %s
1457
- lifecycle {
1458
- ignore_changes = [instance_type]
1459
- }
1460
- }
1461
- ` , sgs )
1366
+ orderly_security_groups = ["sg-cm7fbbf3", "sg-kensue7b", "sg-05f7wnhn"]
1462
1367
}
1368
+ `
0 commit comments