@@ -21,7 +21,7 @@ const (
2121func TestAccTencentCloudImageResource (t * testing.T ) {
2222 t .Parallel ()
2323 resource .Test (t , resource.TestCase {
24- PreCheck : func () { tcacctest .AccPreCheckCommon ( t , tcacctest . ACCOUNT_TYPE_PREPAY ) },
24+ PreCheck : func () { tcacctest .AccPreCheck ( t ) },
2525 Providers : tcacctest .AccProviders ,
2626 CheckDestroy : testAccCheckImageDestroy ,
2727 Steps : []resource.TestStep {
@@ -57,7 +57,7 @@ func TestAccTencentCloudImageResource(t *testing.T) {
5757 Check : resource .ComposeTestCheckFunc (
5858 testAccCheckImageExists (ImageInstance ),
5959 resource .TestCheckResourceAttr (ImageInstance , "image_name" , "image-instance-keep" ),
60- resource .TestCheckResourceAttr (ImageInstance , "instance_id" , tcacctest . DefaultCvmId ),
60+ resource .TestCheckResourceAttrSet (ImageInstance , "instance_id" ),
6161 resource .TestCheckResourceAttr (ImageInstance , "data_disk_ids.#" , "1" ),
6262 resource .TestCheckResourceAttr (ImageInstance , "image_description" , "create image with instance" ),
6363 ),
@@ -66,8 +66,6 @@ func TestAccTencentCloudImageResource(t *testing.T) {
6666 Config : testAccImageWithInstanceUpdate ,
6767 Check : resource .ComposeAggregateTestCheckFunc (
6868 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" ),
7169 resource .TestCheckResourceAttr (ImageInstance , "image_description" , "update image with instance" ),
7270 ),
7371 },
@@ -151,18 +149,117 @@ const (
151149 }`
152150
153151 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+
154202 resource "tencentcloud_image" "image_instance" {
155203 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 ]
158206 image_description = "create image with instance"
159207 }`
160208
161209 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+
162259 resource "tencentcloud_image" "image_instance" {
163260 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 ]
166263 image_description = "update image with instance"
167264 }`
168265)
0 commit comments