@@ -21,7 +21,7 @@ const (
21
21
func TestAccTencentCloudImageResource (t * testing.T ) {
22
22
t .Parallel ()
23
23
resource .Test (t , resource.TestCase {
24
- PreCheck : func () { tcacctest .AccPreCheckCommon ( t , tcacctest . ACCOUNT_TYPE_PREPAY ) },
24
+ PreCheck : func () { tcacctest .AccPreCheck ( t ) },
25
25
Providers : tcacctest .AccProviders ,
26
26
CheckDestroy : testAccCheckImageDestroy ,
27
27
Steps : []resource.TestStep {
@@ -57,7 +57,7 @@ func TestAccTencentCloudImageResource(t *testing.T) {
57
57
Check : resource .ComposeTestCheckFunc (
58
58
testAccCheckImageExists (ImageInstance ),
59
59
resource .TestCheckResourceAttr (ImageInstance , "image_name" , "image-instance-keep" ),
60
- resource .TestCheckResourceAttr (ImageInstance , "instance_id" , tcacctest . DefaultCvmId ),
60
+ resource .TestCheckResourceAttrSet (ImageInstance , "instance_id" ),
61
61
resource .TestCheckResourceAttr (ImageInstance , "data_disk_ids.#" , "1" ),
62
62
resource .TestCheckResourceAttr (ImageInstance , "image_description" , "create image with instance" ),
63
63
),
@@ -66,8 +66,6 @@ func TestAccTencentCloudImageResource(t *testing.T) {
66
66
Config : testAccImageWithInstanceUpdate ,
67
67
Check : resource .ComposeAggregateTestCheckFunc (
68
68
resource .TestCheckResourceAttr (ImageInstance , "image_name" , "image-instance-update-keep" ),
69
- resource .TestCheckResourceAttr (ImageInstance , "instance_id" , tcacctest .DefaultCvmId ),
70
- resource .TestCheckResourceAttr (ImageInstance , "data_disk_ids.#" , "1" ),
71
69
resource .TestCheckResourceAttr (ImageInstance , "image_description" , "update image with instance" ),
72
70
),
73
71
},
@@ -151,18 +149,117 @@ const (
151
149
}`
152
150
153
151
testAccImageWithInstance = tcacctest .DefaultCvmImageVariable + `
152
+
153
+ data "tencentcloud_availability_zones" "default" {
154
+ }
155
+ data "tencentcloud_images" "default" {
156
+ image_type = ["PUBLIC_IMAGE"]
157
+ image_name_regex = "Final"
158
+ }
159
+ data "tencentcloud_images" "testing" {
160
+ image_type = ["PUBLIC_IMAGE"]
161
+ }
162
+ data "tencentcloud_instance_types" "default" {
163
+
164
+ filter {
165
+ name = "instance-family"
166
+ values = ["S4","SA2"]
167
+ }
168
+ filter {
169
+ values = ["ap-guangzhou-7"]
170
+ name = "zone"
171
+ }
172
+ cpu_core_count = 2
173
+ memory_size = 2
174
+ exclude_sold_out = true
175
+ }
176
+ resource "tencentcloud_vpc" "vpc" {
177
+ name = "image-vpc"
178
+ cidr_block = "10.0.0.0/16"
179
+ }
180
+ resource "tencentcloud_subnet" "subnet" {
181
+ vpc_id = tencentcloud_vpc.vpc.id
182
+ name = "image-subnet"
183
+ cidr_block = "10.0.0.0/16"
184
+ availability_zone = "ap-guangzhou-7"
185
+ }
186
+ resource "tencentcloud_instance" "cvm_image" {
187
+ subnet_id = tencentcloud_subnet.subnet.id
188
+ system_disk_type = "CLOUD_PREMIUM"
189
+ project_id = 0
190
+ instance_name = "cvm-image"
191
+ availability_zone = "ap-guangzhou-7"
192
+ image_id = data.tencentcloud_images.default.images.0.image_id
193
+ instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type
194
+ vpc_id = tencentcloud_vpc.vpc.id
195
+ data_disks {
196
+ delete_with_instance = true
197
+ data_disk_type = "CLOUD_PREMIUM"
198
+ data_disk_size = 100
199
+ }
200
+ }
201
+
154
202
resource "tencentcloud_image" "image_instance" {
155
203
image_name = "image-instance-keep"
156
- instance_id = var.cvm_id
157
- data_disk_ids = [var.disk_id ]
204
+ instance_id = tencentcloud_instance.cvm_image.id
205
+ data_disk_ids = [tencentcloud_instance.cvm_image.data_disks.0.data_disk_id ]
158
206
image_description = "create image with instance"
159
207
}`
160
208
161
209
testAccImageWithInstanceUpdate = tcacctest .DefaultCvmImageVariable + `
210
+ data "tencentcloud_availability_zones" "default" {
211
+ }
212
+ data "tencentcloud_images" "default" {
213
+ image_type = ["PUBLIC_IMAGE"]
214
+ image_name_regex = "Final"
215
+ }
216
+ data "tencentcloud_images" "testing" {
217
+ image_type = ["PUBLIC_IMAGE"]
218
+ }
219
+ data "tencentcloud_instance_types" "default" {
220
+
221
+ filter {
222
+ name = "instance-family"
223
+ values = ["S4","SA2"]
224
+ }
225
+ filter {
226
+ values = ["ap-guangzhou-7"]
227
+ name = "zone"
228
+ }
229
+ cpu_core_count = 2
230
+ memory_size = 2
231
+ exclude_sold_out = true
232
+ }
233
+ resource "tencentcloud_vpc" "vpc" {
234
+ name = "image-vpc"
235
+ cidr_block = "10.0.0.0/16"
236
+ }
237
+ resource "tencentcloud_subnet" "subnet" {
238
+ vpc_id = tencentcloud_vpc.vpc.id
239
+ name = "image-subnet"
240
+ cidr_block = "10.0.0.0/16"
241
+ availability_zone = "ap-guangzhou-7"
242
+ }
243
+ resource "tencentcloud_instance" "cvm_image" {
244
+ subnet_id = tencentcloud_subnet.subnet.id
245
+ system_disk_type = "CLOUD_PREMIUM"
246
+ project_id = 0
247
+ instance_name = "cvm-image"
248
+ availability_zone = "ap-guangzhou-7"
249
+ image_id = data.tencentcloud_images.default.images.0.image_id
250
+ instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type
251
+ vpc_id = tencentcloud_vpc.vpc.id
252
+ data_disks {
253
+ delete_with_instance = true
254
+ data_disk_type = "CLOUD_PREMIUM"
255
+ data_disk_size = 100
256
+ }
257
+ }
258
+
162
259
resource "tencentcloud_image" "image_instance" {
163
260
image_name = "image-instance-update-keep"
164
- instance_id = var.cvm_id
165
- data_disk_ids = [var.disk_id ]
261
+ instance_id = tencentcloud_instance.cvm_image.id
262
+ data_disk_ids = [tencentcloud_instance.cvm_image.data_disks.0.data_disk_id ]
166
263
image_description = "update image with instance"
167
264
}`
168
265
)
0 commit comments