Skip to content

Commit 940459e

Browse files
authored
Feat/cvm testing (#2365)
* feat: cvm case * feat: cvm case * feat: cvm case * feat: cvm case
1 parent 582ae7d commit 940459e

File tree

2 files changed

+187
-3
lines changed

2 files changed

+187
-3
lines changed

tencentcloud/basic_test.go

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,13 @@ const (
6262
defaultVpcCidr = "172.16.0.0/16"
6363
defaultVpcCidrLess = "172.16.0.0/18"
6464

65-
defaultCvmAZone = "ap-guangzhou-7"
66-
defaultCvmVpcId = "vpc-l0dw94uh"
67-
defaultCvmSubnetId = "subnet-ccj2qg0m"
65+
defaultCvmAZone = "ap-guangzhou-7"
66+
defaultCvmVpcId = "vpc-l0dw94uh"
67+
defaultCvmSubnetId = "subnet-ccj2qg0m"
68+
defaultCvmTestingAZone = "ap-guangzhou-2"
69+
defaultCvmTestingVpcId = "vpc-701bm52d"
70+
defaultCvmTestingSubnetId = "subnet-1q62lj3m"
71+
defaultCvmTestingImgId = "img-eb30mz89"
6872

6973
defaultAZone = "ap-guangzhou-3"
7074
defaultSubnetId = "subnet-enm92y0m"
@@ -247,6 +251,22 @@ variable "availability_cvm_zone" {
247251
default = "` + defaultCvmAZone + `"
248252
}
249253
254+
variable "availability_cvm_testing_zone" {
255+
default = "` + defaultCvmTestingAZone + `"
256+
}
257+
258+
variable "cvm_testing_vpc_id" {
259+
default = "` + defaultCvmTestingVpcId + `"
260+
}
261+
262+
variable "cvm_testing_subnet_id" {
263+
default = "` + defaultCvmTestingSubnetId + `"
264+
}
265+
266+
variable "cvm_testing_image_id" {
267+
default = "` + defaultCvmTestingImgId + `"
268+
}
269+
250270
variable "cvm_vpc_id" {
251271
default = "` + defaultCvmVpcId + `"
252272
}
@@ -301,6 +321,10 @@ data "tencentcloud_images" "default" {
301321
image_name_regex = "Final"
302322
}
303323
324+
data "tencentcloud_images" "testing" {
325+
image_type = ["PUBLIC_IMAGE"]
326+
}
327+
304328
data "tencentcloud_instance_types" "default" {
305329
filter {
306330
name = "zone"
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
package tencentcloud
2+
3+
import (
4+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
5+
"testing"
6+
)
7+
8+
func TestAccTencentCloudTestingCvmInstanceResource_Basic(t *testing.T) {
9+
t.Parallel()
10+
11+
id := "tencentcloud_instance.cvm_basic"
12+
resource.Test(t, resource.TestCase{
13+
PreCheck: func() { testAccPreCheck(t) },
14+
IDRefreshName: id,
15+
Providers: testAccProviders,
16+
CheckDestroy: testAccCheckInstanceDestroy,
17+
Steps: []resource.TestStep{
18+
{
19+
PreConfig: func() { testAccStepPreConfigSetTempAKSK(t, ACCOUNT_TYPE_COMMON) },
20+
Config: testAccTencentCloudTestingCvmInstanceBasic,
21+
Check: resource.ComposeTestCheckFunc(
22+
testAccCheckTencentCloudDataSourceID(id),
23+
testAccCheckTencentCloudInstanceExists(id),
24+
resource.TestCheckResourceAttr(id, "instance_status", "RUNNING"),
25+
resource.TestCheckResourceAttrSet(id, "private_ip"),
26+
resource.TestCheckResourceAttrSet(id, "vpc_id"),
27+
resource.TestCheckResourceAttrSet(id, "subnet_id"),
28+
resource.TestCheckResourceAttrSet(id, "project_id"),
29+
),
30+
},
31+
{
32+
PreConfig: func() { testAccStepPreConfigSetTempAKSK(t, ACCOUNT_TYPE_COMMON) },
33+
Config: testAccTencentCloudTestingCvmInstanceModifyInstanceType,
34+
Check: resource.ComposeTestCheckFunc(
35+
testAccCheckTencentCloudInstanceExists(id),
36+
resource.TestCheckResourceAttr(id, "instance_status", "RUNNING"),
37+
resource.TestCheckResourceAttrSet(id, "instance_type"),
38+
),
39+
},
40+
},
41+
})
42+
}
43+
44+
func TestAccTencentCloudTestingCvmInstanceResource_WithDataDisk(t *testing.T) {
45+
t.Parallel()
46+
47+
id := "tencentcloud_instance.foo"
48+
resource.Test(t, resource.TestCase{
49+
PreCheck: func() { testAccPreCheck(t) },
50+
IDRefreshName: id,
51+
Providers: testAccProviders,
52+
CheckDestroy: testAccCheckInstanceDestroy,
53+
Steps: []resource.TestStep{
54+
{
55+
PreConfig: func() { testAccStepPreConfigSetTempAKSK(t, ACCOUNT_TYPE_COMMON) },
56+
Config: testAccTencentCloudTestingInstanceWithDataDisk,
57+
Check: resource.ComposeTestCheckFunc(
58+
testAccCheckTencentCloudDataSourceID(id),
59+
testAccCheckTencentCloudInstanceExists(id),
60+
resource.TestCheckResourceAttr(id, "instance_status", "RUNNING"),
61+
resource.TestCheckResourceAttr(id, "system_disk_size", "100"),
62+
resource.TestCheckResourceAttr(id, "system_disk_type", "CLOUD_PREMIUM"),
63+
resource.TestCheckResourceAttr(id, "data_disks.0.data_disk_type", "CLOUD_PREMIUM"),
64+
resource.TestCheckResourceAttr(id, "data_disks.0.data_disk_size", "100"),
65+
resource.TestCheckResourceAttr(id, "data_disks.0.data_disk_snapshot_id", ""),
66+
),
67+
},
68+
{
69+
PreConfig: func() { testAccStepPreConfigSetTempAKSK(t, ACCOUNT_TYPE_COMMON) },
70+
Config: testAccTencentCloudTestingInstanceWithDataDiskUpdate,
71+
Check: resource.ComposeTestCheckFunc(
72+
testAccCheckTencentCloudDataSourceID(id),
73+
testAccCheckTencentCloudInstanceExists(id),
74+
resource.TestCheckResourceAttr(id, "instance_status", "RUNNING"),
75+
resource.TestCheckResourceAttr(id, "system_disk_size", "100"),
76+
resource.TestCheckResourceAttr(id, "system_disk_type", "CLOUD_PREMIUM"),
77+
resource.TestCheckResourceAttr(id, "data_disks.0.data_disk_type", "CLOUD_PREMIUM"),
78+
resource.TestCheckResourceAttr(id, "data_disks.0.data_disk_size", "150"),
79+
resource.TestCheckResourceAttr(id, "data_disks.0.data_disk_snapshot_id", ""),
80+
resource.TestCheckResourceAttr(id, "data_disks.1.data_disk_type", "CLOUD_PREMIUM"),
81+
resource.TestCheckResourceAttr(id, "data_disks.1.data_disk_size", "150"),
82+
),
83+
},
84+
},
85+
})
86+
}
87+
88+
const testAccTencentCloudTestingCvmInstanceBasic = defaultInstanceVariable + `
89+
resource "tencentcloud_instance" "cvm_basic" {
90+
instance_name = var.instance_name
91+
availability_zone = var.availability_cvm_testing_zone
92+
image_id = var.cvm_testing_image_id
93+
instance_type = "S2.MEDIUM2"
94+
vpc_id = var.cvm_testing_vpc_id
95+
subnet_id = var.cvm_testing_subnet_id
96+
system_disk_type = "CLOUD_PREMIUM"
97+
project_id = 0
98+
}
99+
`
100+
const testAccTencentCloudTestingCvmInstanceModifyInstanceType = defaultInstanceVariable + `
101+
102+
resource "tencentcloud_instance" "cvm_basic" {
103+
instance_name = var.instance_name
104+
availability_zone = var.availability_cvm_testing_zone
105+
image_id = var.cvm_testing_image_id
106+
instance_type = "S2.MEDIUM2"
107+
vpc_id = var.cvm_testing_vpc_id
108+
subnet_id = var.cvm_testing_subnet_id
109+
system_disk_type = "CLOUD_PREMIUM"
110+
project_id = 0
111+
}
112+
`
113+
114+
const testAccTencentCloudTestingInstanceWithDataDisk = defaultInstanceVariable + `
115+
resource "tencentcloud_instance" "foo" {
116+
instance_name = var.instance_name
117+
availability_zone = var.availability_cvm_testing_zone
118+
image_id = var.cvm_testing_image_id
119+
instance_type = "S2.MEDIUM2"
120+
121+
system_disk_type = "CLOUD_PREMIUM"
122+
system_disk_size = 100
123+
124+
data_disks {
125+
data_disk_type = "CLOUD_PREMIUM"
126+
data_disk_size = 100
127+
delete_with_instance = true
128+
}
129+
130+
disable_security_service = true
131+
disable_monitor_service = true
132+
}
133+
`
134+
135+
const testAccTencentCloudTestingInstanceWithDataDiskUpdate = defaultInstanceVariable + `
136+
resource "tencentcloud_instance" "foo" {
137+
instance_name = var.instance_name
138+
availability_zone = var.availability_cvm_testing_zone
139+
image_id = var.cvm_testing_image_id
140+
instance_type = "S2.MEDIUM2"
141+
142+
system_disk_type = "CLOUD_PREMIUM"
143+
system_disk_size = 100
144+
145+
data_disks {
146+
data_disk_type = "CLOUD_PREMIUM"
147+
data_disk_size = 150
148+
delete_with_instance = true
149+
}
150+
151+
data_disks {
152+
data_disk_type = "CLOUD_PREMIUM"
153+
data_disk_size = 150
154+
delete_with_instance = true
155+
}
156+
157+
disable_security_service = true
158+
disable_monitor_service = true
159+
}
160+
`

0 commit comments

Comments
 (0)