Skip to content

Commit 7c0613b

Browse files
author
mikatong
committed
fix cvm test
1 parent a016c4a commit 7c0613b

File tree

1 file changed

+129
-12
lines changed

1 file changed

+129
-12
lines changed

tencentcloud/services/cvm/resource_tc_instance_test.go

Lines changed: 129 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -783,30 +783,57 @@ func testAccCheckInstanceDestroy(s *terraform.State) error {
783783
}
784784

785785
const testAccTencentCloudInstanceBasic = tcacctest.DefaultInstanceVariable + `
786+
resource "tencentcloud_vpc" "vpc" {
787+
name = "cvm-basic-vpc"
788+
cidr_block = "10.0.0.0/16"
789+
}
790+
791+
resource "tencentcloud_subnet" "subnet" {
792+
vpc_id = tencentcloud_vpc.vpc.id
793+
name = "cvm-basic-subnet"
794+
cidr_block = "10.0.0.0/16"
795+
availability_zone = var.availability_cvm_zone
796+
}
797+
786798
resource "tencentcloud_instance" "cvm_basic" {
787799
instance_name = var.instance_name
788800
availability_zone = var.availability_cvm_zone
789801
image_id = data.tencentcloud_images.default.images.0.image_id
790802
instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type
791-
vpc_id = var.cvm_vpc_id
792-
subnet_id = var.cvm_subnet_id
803+
vpc_id = tencentcloud_vpc.vpc.id
804+
subnet_id = tencentcloud_subnet.subnet.id
793805
system_disk_type = "CLOUD_PREMIUM"
794806
project_id = 0
795807
796808
tags = {
797809
hostname = "tci"
798810
}
811+
lifecycle {
812+
ignore_changes = [instance_type]
813+
}
799814
}
800815
`
801816

802817
const testAccTencentCloudInstancePrepaidBasic = tcacctest.DefaultInstanceVariable + `
818+
resource "tencentcloud_vpc" "vpc" {
819+
name = "cvm-prepaid-basic-vpc"
820+
cidr_block = "10.0.0.0/16"
821+
}
822+
823+
resource "tencentcloud_subnet" "subnet" {
824+
vpc_id = tencentcloud_vpc.vpc.id
825+
name = "cvm-prepaid-basic-subnet"
826+
cidr_block = "10.0.0.0/16"
827+
availability_zone = var.availability_cvm_zone
828+
}
829+
803830
resource "tencentcloud_instance" "cvm_prepaid_basic" {
804831
instance_name = var.instance_name
805832
availability_zone = var.availability_cvm_zone
806833
image_id = data.tencentcloud_images.default.images.0.image_id
807834
instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type
808-
vpc_id = var.cvm_vpc_id
809-
subnet_id = var.cvm_subnet_id
835+
vpc_id = tencentcloud_vpc.vpc.id
836+
subnet_id = tencentcloud_subnet.subnet.id
810837
system_disk_type = "CLOUD_PREMIUM"
811838
project_id = 0
812839
instance_charge_type = "PREPAID"
@@ -820,13 +847,25 @@ resource "tencentcloud_instance" "cvm_prepaid_basic" {
820847
`
821848

822849
const testAccTencentCloudInstanceWithDataDiskOrder = tcacctest.DefaultInstanceVariable + `
850+
resource "tencentcloud_vpc" "vpc" {
851+
name = "cvm-with-cbs-order-vpc"
852+
cidr_block = "10.0.0.0/16"
853+
}
854+
855+
resource "tencentcloud_subnet" "subnet" {
856+
vpc_id = tencentcloud_vpc.vpc.id
857+
name = "cvm-with-cbs-order-subnet"
858+
cidr_block = "10.0.0.0/16"
859+
availability_zone = var.availability_cvm_zone
860+
}
861+
823862
resource "tencentcloud_instance" "foo" {
824863
instance_name = var.instance_name
825864
availability_zone = var.availability_cvm_zone
826865
image_id = data.tencentcloud_images.default.images.0.image_id
827866
instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type
828-
vpc_id = var.cvm_vpc_id
829-
subnet_id = var.cvm_subnet_id
867+
vpc_id = tencentcloud_vpc.vpc.id
868+
subnet_id = tencentcloud_subnet.subnet.id
830869
system_disk_type = "CLOUD_PREMIUM"
831870
project_id = 0
832871
@@ -849,13 +888,25 @@ resource "tencentcloud_instance" "foo" {
849888
`
850889

851890
const testAccTencentCloudInstanceAddDataDiskByCbs = tcacctest.DefaultInstanceVariable + `
891+
resource "tencentcloud_vpc" "vpc" {
892+
name = "cvm-attach-cbs-vpc"
893+
cidr_block = "10.0.0.0/16"
894+
}
895+
896+
resource "tencentcloud_subnet" "subnet" {
897+
vpc_id = tencentcloud_vpc.vpc.id
898+
name = "cvm-attach-cbs-subnet"
899+
cidr_block = "10.0.0.0/16"
900+
availability_zone = var.availability_cvm_zone
901+
}
902+
852903
resource "tencentcloud_instance" "cvm_add_data_disk_by_cbs" {
853904
instance_name = "cvm-add-data-disk-by-cbs"
854905
availability_zone = var.availability_cvm_zone
855906
image_id = data.tencentcloud_images.default.images.0.image_id
856907
instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type
857-
vpc_id = var.cvm_vpc_id
858-
subnet_id = var.cvm_subnet_id
908+
vpc_id = tencentcloud_vpc.vpc.id
909+
subnet_id = tencentcloud_subnet.subnet.id
859910
system_disk_type = "CLOUD_PREMIUM"
860911
project_id = 0
861912
}
@@ -904,6 +955,9 @@ resource "tencentcloud_instance" "foo" {
904955
instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type
905956
system_disk_type = "CLOUD_PREMIUM"
906957
force_delete = true
958+
lifecycle {
959+
ignore_changes = [instance_type]
960+
}
907961
}
908962
`
909963

@@ -928,6 +982,9 @@ resource "tencentcloud_instance" "foo" {
928982
instance_charge_type_prepaid_period = 1
929983
instance_charge_type_prepaid_renew_flag = "NOTIFY_AND_MANUAL_RENEW"
930984
force_delete = true
985+
lifecycle {
986+
ignore_changes = [instance_type]
987+
}
931988
}
932989
`
933990

@@ -939,19 +996,34 @@ data "tencentcloud_instance_types" "new_type" {
939996
memory_size = 2
940997
}
941998
999+
resource "tencentcloud_vpc" "vpc" {
1000+
name = "cvm-basic-vpc"
1001+
cidr_block = "10.0.0.0/16"
1002+
}
1003+
1004+
resource "tencentcloud_subnet" "subnet" {
1005+
vpc_id = tencentcloud_vpc.vpc.id
1006+
name = "cvm-basic-subnet"
1007+
cidr_block = "10.0.0.0/16"
1008+
availability_zone = var.availability_cvm_zone
1009+
}
1010+
9421011
resource "tencentcloud_instance" "cvm_basic" {
9431012
instance_name = var.instance_name
9441013
availability_zone = var.availability_cvm_zone
9451014
image_id = data.tencentcloud_images.default.images.0.image_id
9461015
instance_type = data.tencentcloud_instance_types.new_type.instance_types.0.instance_type
947-
vpc_id = var.cvm_vpc_id
948-
subnet_id = var.cvm_subnet_id
1016+
vpc_id = tencentcloud_vpc.vpc.id
1017+
subnet_id = tencentcloud_subnet.subnet.id
9491018
system_disk_type = "CLOUD_PREMIUM"
9501019
project_id = 0
9511020
9521021
tags = {
9531022
hostname = "tci"
9541023
}
1024+
lifecycle {
1025+
ignore_changes = [instance_type]
1026+
}
9551027
}
9561028
`
9571029

@@ -981,6 +1053,9 @@ resource "tencentcloud_instance" "foo" {
9811053
9821054
disable_security_service = true
9831055
disable_monitor_service = true
1056+
lifecycle {
1057+
ignore_changes = [instance_type]
1058+
}
9841059
}
9851060
`
9861061

@@ -1078,6 +1153,9 @@ resource "tencentcloud_instance" "foo" {
10781153
10791154
disable_security_service = true
10801155
disable_monitor_service = true
1156+
lifecycle {
1157+
ignore_changes = [instance_type]
1158+
}
10811159
}
10821160
`
10831161

@@ -1091,6 +1169,9 @@ resource "tencentcloud_instance" "foo" {
10911169
instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type
10921170
allocate_public_ip = %s
10931171
system_disk_type = "CLOUD_PREMIUM"
1172+
lifecycle {
1173+
ignore_changes = [instance_type]
1174+
}
10941175
}
10951176
`,
10961177
hasPublicIp,
@@ -1108,21 +1189,36 @@ resource "tencentcloud_instance" "foo" {
11081189
internet_max_bandwidth_out = %d
11091190
allocate_public_ip = %s
11101191
system_disk_type = "CLOUD_PREMIUM"
1192+
lifecycle {
1193+
ignore_changes = [instance_type]
1194+
}
11111195
}
11121196
`,
11131197
maxBandWidthOut, hasPublicIp,
11141198
)
11151199
}
11161200

11171201
const testAccTencentCloudInstanceWithPrivateIP = tcacctest.DefaultInstanceVariable + `
1202+
resource "tencentcloud_vpc" "vpc" {
1203+
name = "cvm-with-privateip-vpc"
1204+
cidr_block = "10.0.0.0/16"
1205+
}
1206+
1207+
resource "tencentcloud_subnet" "subnet" {
1208+
vpc_id = tencentcloud_vpc.vpc.id
1209+
name = "cvm-with-privateip-subnet"
1210+
cidr_block = "10.0.0.0/16"
1211+
availability_zone = var.availability_cvm_zone
1212+
}
1213+
11181214
resource "tencentcloud_instance" "foo" {
11191215
instance_name = var.instance_name
11201216
availability_zone = var.availability_cvm_zone
11211217
image_id = data.tencentcloud_images.default.images.0.image_id
11221218
instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type
11231219
system_disk_type = "CLOUD_PREMIUM"
1124-
vpc_id = var.cvm_vpc_id
1125-
subnet_id = var.cvm_subnet_id
1220+
vpc_id = tencentcloud_vpc.vpc.id
1221+
subnet_id = tencentcloud_subnet.subnet.id
11261222
private_ip = "10.0.0.123"
11271223
}
11281224
`
@@ -1134,6 +1230,9 @@ resource "tencentcloud_instance" "foo" {
11341230
image_id = data.tencentcloud_images.default.images.0.image_id
11351231
instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type
11361232
system_disk_type = "CLOUD_PREMIUM"
1233+
lifecycle {
1234+
ignore_changes = [instance_type]
1235+
}
11371236
}
11381237
`
11391238

@@ -1163,6 +1262,9 @@ resource "tencentcloud_instance" "foo" {
11631262
instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type
11641263
key_ids = %s
11651264
system_disk_type = "CLOUD_PREMIUM"
1265+
lifecycle {
1266+
ignore_changes = [instance_type]
1267+
}
11661268
}
11671269
`,
11681270
keyIds,
@@ -1179,6 +1281,9 @@ resource "tencentcloud_instance" "foo" {
11791281
instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type
11801282
password = "%s"
11811283
system_disk_type = "CLOUD_PREMIUM"
1284+
lifecycle {
1285+
ignore_changes = [instance_type]
1286+
}
11821287
}
11831288
`,
11841289
password,
@@ -1209,6 +1314,9 @@ resource "tencentcloud_instance" "foo" {
12091314
image_id = data.tencentcloud_images.default.images.0.image_id
12101315
instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type
12111316
system_disk_type = "CLOUD_PREMIUM"
1317+
lifecycle {
1318+
ignore_changes = [instance_type]
1319+
}
12121320
}
12131321
`,
12141322
instanceName,
@@ -1264,6 +1372,9 @@ resource "tencentcloud_instance" "foo" {
12641372
instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type
12651373
system_disk_type = "CLOUD_PREMIUM"
12661374
security_groups = %s
1375+
lifecycle {
1376+
ignore_changes = [instance_type]
1377+
}
12671378
}
12681379
`,
12691380
ids,
@@ -1284,6 +1395,9 @@ resource "tencentcloud_instance" "foo" {
12841395
data_disk_size = 150
12851396
delete_with_instance = true
12861397
}
1398+
lifecycle {
1399+
ignore_changes = [instance_type]
1400+
}
12871401
tags = %s
12881402
}
12891403
`,
@@ -1340,6 +1454,9 @@ resource "tencentcloud_instance" "cvm_with_orderly_sg" {
13401454
instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type
13411455
system_disk_type = "CLOUD_PREMIUM"
13421456
orderly_security_groups = %s
1457+
lifecycle {
1458+
ignore_changes = [instance_type]
1459+
}
13431460
}
13441461
`, sgs)
13451462
}

0 commit comments

Comments
 (0)