From 3059992ea3775b6f691ef24db0cedb5756922a0a Mon Sep 17 00:00:00 2001 From: mikatong Date: Wed, 18 May 2022 17:22:29 +0800 Subject: [PATCH] fix: cvm image --- .../tencentcloud-persistent-resource/cvm.tf | 30 +++++++++++++++++++ tencentcloud/basic_test.go | 19 ++++++++++++ tencentcloud/resource_tc_image_test.go | 24 +++++++-------- 3 files changed, 61 insertions(+), 12 deletions(-) diff --git a/examples/tencentcloud-persistent-resource/cvm.tf b/examples/tencentcloud-persistent-resource/cvm.tf index 1fe84b7881..703d6f1832 100644 --- a/examples/tencentcloud-persistent-resource/cvm.tf +++ b/examples/tencentcloud-persistent-resource/cvm.tf @@ -2,4 +2,34 @@ resource "tencentcloud_instance" "cvm" { availability_zone = var.default_az image_id = var.image_id instance_name = var.cvm_name +} + +data "tencentcloud_images" "default" { + image_type = ["PUBLIC_IMAGE"] + image_name_regex = "Final" +} + +data "tencentcloud_instance_types" "default" { + filter { + name = "zone" + values = ["ap-guangzhou-3"] + } + cpu_core_count = 2 + exclude_sold_out = true +} + +resource "tencentcloud_instance" "foo" { + instance_name = "keep-test-image-cvm" + availability_zone = "ap-guangzhou-3" + image_id = data.tencentcloud_images.default.images.0.image_id + instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type + vpc_id = "vpc-68vi2d3h" + subnet_id = "subnet-ob6clqwk" + system_disk_type = "CLOUD_PREMIUM" + project_id = 0 + data_disks { + data_disk_type = "CLOUD_PREMIUM" + data_disk_size = 50 + encrypt = false + } } \ No newline at end of file diff --git a/tencentcloud/basic_test.go b/tencentcloud/basic_test.go index f22c847d45..ed7e41f2b0 100644 --- a/tencentcloud/basic_test.go +++ b/tencentcloud/basic_test.go @@ -114,6 +114,25 @@ variable "sg_id" { } ` +//cvm-image +const ( + defaultCvmId = "ins-8oqqya08" + defaultDiskId = "disk-5jjrs2lm" + defaultSnapId = "snap-8f2updnb" +) + +const defaultCvmImageVariable = ` +variable "cvm_id" { + default = "` + defaultCvmId + `" +} +variable "disk_id" { + default = "` + defaultDiskId + `" +} +variable "snap_id" { + default = "` + defaultSnapId + `" +} +` + //ckafka const ( defaultKafkaInstanceId = "ckafka-vv7wpvae" diff --git a/tencentcloud/resource_tc_image_test.go b/tencentcloud/resource_tc_image_test.go index c019d420d6..e82e5cf224 100644 --- a/tencentcloud/resource_tc_image_test.go +++ b/tencentcloud/resource_tc_image_test.go @@ -53,7 +53,7 @@ func TestAccTencentCloudImageResource(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckImageExists(ImageInstance), resource.TestCheckResourceAttr(ImageInstance, "image_name", "image-instance-keep"), - resource.TestCheckResourceAttr(ImageInstance, "instance_id", "ins-fodds4y2"), + resource.TestCheckResourceAttr(ImageInstance, "instance_id", defaultCvmId), resource.TestCheckResourceAttr(ImageInstance, "data_disk_ids.#", "1"), resource.TestCheckResourceAttr(ImageInstance, "image_description", "create image with instance"), ), @@ -62,7 +62,7 @@ func TestAccTencentCloudImageResource(t *testing.T) { Config: testAccImageWithInstanceUpdate, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr(ImageInstance, "image_name", "image-instance-update-keep"), - resource.TestCheckResourceAttr(ImageInstance, "instance_id", "ins-fodds4y2"), + resource.TestCheckResourceAttr(ImageInstance, "instance_id", defaultCvmId), resource.TestCheckResourceAttr(ImageInstance, "data_disk_ids.#", "1"), resource.TestCheckResourceAttr(ImageInstance, "image_description", "update image with instance"), ), @@ -134,35 +134,35 @@ func testAccCheckImageExists(n string) resource.TestCheckFunc { } const ( - testAccImageWithSnapShot = ` + testAccImageWithSnapShot = defaultCvmImageVariable + ` resource "tencentcloud_image" "image_snap" { image_name = "image-snapshot-keep" - snapshot_ids = ["snap-8f2updnb"] + snapshot_ids = [var.snap_id] force_poweroff = true image_description = "create image with snapshot" }` - testAccImageWithSnapShotUpdate = ` + testAccImageWithSnapShotUpdate = defaultCvmImageVariable + ` resource "tencentcloud_image" "image_snap" { image_name = "image-snapshot-update-keep" - snapshot_ids = ["snap-8f2updnb"] + snapshot_ids = [var.snap_id] force_poweroff = false image_description = "update image with snapshot" }` - testAccImageWithInstance = ` + testAccImageWithInstance = defaultCvmImageVariable + ` resource "tencentcloud_image" "image_instance" { image_name = "image-instance-keep" - instance_id = "ins-fodds4y2" - data_disk_ids = ["disk-mrnskm5i"] + instance_id = var.cvm_id + data_disk_ids = [var.disk_id] image_description = "create image with instance" }` - testAccImageWithInstanceUpdate = ` + testAccImageWithInstanceUpdate = defaultCvmImageVariable + ` resource "tencentcloud_image" "image_instance" { image_name = "image-instance-update-keep" - instance_id = "ins-fodds4y2" - data_disk_ids = ["disk-mrnskm5i"] + instance_id = var.cvm_id + data_disk_ids = [var.disk_id] image_description = "update image with instance" }` )