Skip to content

Commit 756ce68

Browse files
tongyimingmikatong
andauthored
fix: cvm image (#1050)
Co-authored-by: mikatong <mikatong@tencent.com>
1 parent f6b9393 commit 756ce68

File tree

3 files changed

+61
-12
lines changed

3 files changed

+61
-12
lines changed

examples/tencentcloud-persistent-resource/cvm.tf

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,34 @@ resource "tencentcloud_instance" "cvm" {
22
availability_zone = var.default_az
33
image_id = var.image_id
44
instance_name = var.cvm_name
5+
}
6+
7+
data "tencentcloud_images" "default" {
8+
image_type = ["PUBLIC_IMAGE"]
9+
image_name_regex = "Final"
10+
}
11+
12+
data "tencentcloud_instance_types" "default" {
13+
filter {
14+
name = "zone"
15+
values = ["ap-guangzhou-3"]
16+
}
17+
cpu_core_count = 2
18+
exclude_sold_out = true
19+
}
20+
21+
resource "tencentcloud_instance" "foo" {
22+
instance_name = "keep-test-image-cvm"
23+
availability_zone = "ap-guangzhou-3"
24+
image_id = data.tencentcloud_images.default.images.0.image_id
25+
instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type
26+
vpc_id = "vpc-68vi2d3h"
27+
subnet_id = "subnet-ob6clqwk"
28+
system_disk_type = "CLOUD_PREMIUM"
29+
project_id = 0
30+
data_disks {
31+
data_disk_type = "CLOUD_PREMIUM"
32+
data_disk_size = 50
33+
encrypt = false
34+
}
535
}

tencentcloud/basic_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,25 @@ variable "sg_id" {
114114
}
115115
`
116116

117+
//cvm-image
118+
const (
119+
defaultCvmId = "ins-8oqqya08"
120+
defaultDiskId = "disk-5jjrs2lm"
121+
defaultSnapId = "snap-8f2updnb"
122+
)
123+
124+
const defaultCvmImageVariable = `
125+
variable "cvm_id" {
126+
default = "` + defaultCvmId + `"
127+
}
128+
variable "disk_id" {
129+
default = "` + defaultDiskId + `"
130+
}
131+
variable "snap_id" {
132+
default = "` + defaultSnapId + `"
133+
}
134+
`
135+
117136
//ckafka
118137
const (
119138
defaultKafkaInstanceId = "ckafka-vv7wpvae"

tencentcloud/resource_tc_image_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestAccTencentCloudImageResource(t *testing.T) {
5353
Check: resource.ComposeTestCheckFunc(
5454
testAccCheckImageExists(ImageInstance),
5555
resource.TestCheckResourceAttr(ImageInstance, "image_name", "image-instance-keep"),
56-
resource.TestCheckResourceAttr(ImageInstance, "instance_id", "ins-fodds4y2"),
56+
resource.TestCheckResourceAttr(ImageInstance, "instance_id", defaultCvmId),
5757
resource.TestCheckResourceAttr(ImageInstance, "data_disk_ids.#", "1"),
5858
resource.TestCheckResourceAttr(ImageInstance, "image_description", "create image with instance"),
5959
),
@@ -62,7 +62,7 @@ func TestAccTencentCloudImageResource(t *testing.T) {
6262
Config: testAccImageWithInstanceUpdate,
6363
Check: resource.ComposeAggregateTestCheckFunc(
6464
resource.TestCheckResourceAttr(ImageInstance, "image_name", "image-instance-update-keep"),
65-
resource.TestCheckResourceAttr(ImageInstance, "instance_id", "ins-fodds4y2"),
65+
resource.TestCheckResourceAttr(ImageInstance, "instance_id", defaultCvmId),
6666
resource.TestCheckResourceAttr(ImageInstance, "data_disk_ids.#", "1"),
6767
resource.TestCheckResourceAttr(ImageInstance, "image_description", "update image with instance"),
6868
),
@@ -134,35 +134,35 @@ func testAccCheckImageExists(n string) resource.TestCheckFunc {
134134
}
135135

136136
const (
137-
testAccImageWithSnapShot = `
137+
testAccImageWithSnapShot = defaultCvmImageVariable + `
138138
resource "tencentcloud_image" "image_snap" {
139139
image_name = "image-snapshot-keep"
140-
snapshot_ids = ["snap-8f2updnb"]
140+
snapshot_ids = [var.snap_id]
141141
force_poweroff = true
142142
image_description = "create image with snapshot"
143143
}`
144144

145-
testAccImageWithSnapShotUpdate = `
145+
testAccImageWithSnapShotUpdate = defaultCvmImageVariable + `
146146
resource "tencentcloud_image" "image_snap" {
147147
image_name = "image-snapshot-update-keep"
148-
snapshot_ids = ["snap-8f2updnb"]
148+
snapshot_ids = [var.snap_id]
149149
force_poweroff = false
150150
image_description = "update image with snapshot"
151151
}`
152152

153-
testAccImageWithInstance = `
153+
testAccImageWithInstance = defaultCvmImageVariable + `
154154
resource "tencentcloud_image" "image_instance" {
155155
image_name = "image-instance-keep"
156-
instance_id = "ins-fodds4y2"
157-
data_disk_ids = ["disk-mrnskm5i"]
156+
instance_id = var.cvm_id
157+
data_disk_ids = [var.disk_id]
158158
image_description = "create image with instance"
159159
}`
160160

161-
testAccImageWithInstanceUpdate = `
161+
testAccImageWithInstanceUpdate = defaultCvmImageVariable + `
162162
resource "tencentcloud_image" "image_instance" {
163163
image_name = "image-instance-update-keep"
164-
instance_id = "ins-fodds4y2"
165-
data_disk_ids = ["disk-mrnskm5i"]
164+
instance_id = var.cvm_id
165+
data_disk_ids = [var.disk_id]
166166
image_description = "update image with instance"
167167
}`
168168
)

0 commit comments

Comments
 (0)