From f729a09b8b5f95c96ae44b4555705e9854528d69 Mon Sep 17 00:00:00 2001 From: mikatong Date: Thu, 10 Mar 2022 17:49:23 +0800 Subject: [PATCH 1/3] fix: resource_tc_image & data_source_tc_reserved_instances unit test --- .../data_source_tc_reserved_instances_test.go | 4 ++-- tencentcloud/resource_tc_image_test.go | 22 +++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tencentcloud/data_source_tc_reserved_instances_test.go b/tencentcloud/data_source_tc_reserved_instances_test.go index 7e01070c71..14ed5e09e9 100644 --- a/tencentcloud/data_source_tc_reserved_instances_test.go +++ b/tencentcloud/data_source_tc_reserved_instances_test.go @@ -9,7 +9,7 @@ import ( func TestAccTencentCloudReservedInstancesDataSource(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_INTERNATION) }, Providers: testAccProviders, Steps: []resource.TestStep{ { @@ -24,6 +24,6 @@ func TestAccTencentCloudReservedInstancesDataSource(t *testing.T) { const testAccReservedInstancesDataSource = ` data "tencentcloud_reserved_instances" "instances" { - availability_zone = "ap-guangzhou-2" + availability_zone = "ap-guangzhou-3" } ` diff --git a/tencentcloud/resource_tc_image_test.go b/tencentcloud/resource_tc_image_test.go index 1b1fd8e58b..c019d420d6 100644 --- a/tencentcloud/resource_tc_image_test.go +++ b/tencentcloud/resource_tc_image_test.go @@ -17,7 +17,7 @@ const ( func TestAccTencentCloudImageResource(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_PREPAY) }, Providers: testAccProviders, CheckDestroy: testAccCheckImageDestroy, Steps: []resource.TestStep{ @@ -27,7 +27,7 @@ func TestAccTencentCloudImageResource(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckImageExists(ImageSnap), resource.TestCheckResourceAttr(ImageSnap, "image_name", "image-snapshot-keep"), - resource.TestCheckResourceAttr(ImageSnap, "snapshot_ids.#", "2"), + resource.TestCheckResourceAttr(ImageSnap, "snapshot_ids.#", "1"), resource.TestCheckResourceAttr(ImageSnap, "force_poweroff", "true"), resource.TestCheckResourceAttr(ImageSnap, "image_description", "create image with snapshot"), ), @@ -36,7 +36,7 @@ func TestAccTencentCloudImageResource(t *testing.T) { Config: testAccImageWithSnapShotUpdate, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr(ImageSnap, "image_name", "image-snapshot-update-keep"), - resource.TestCheckResourceAttr(ImageSnap, "snapshot_ids.#", "2"), + resource.TestCheckResourceAttr(ImageSnap, "snapshot_ids.#", "1"), resource.TestCheckResourceAttr(ImageSnap, "force_poweroff", "false"), resource.TestCheckResourceAttr(ImageSnap, "image_description", "update image with snapshot"), ), @@ -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-2ju245xg"), + resource.TestCheckResourceAttr(ImageInstance, "instance_id", "ins-fodds4y2"), 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-2ju245xg"), + resource.TestCheckResourceAttr(ImageInstance, "instance_id", "ins-fodds4y2"), resource.TestCheckResourceAttr(ImageInstance, "data_disk_ids.#", "1"), resource.TestCheckResourceAttr(ImageInstance, "image_description", "update image with instance"), ), @@ -137,7 +137,7 @@ const ( testAccImageWithSnapShot = ` resource "tencentcloud_image" "image_snap" { image_name = "image-snapshot-keep" - snapshot_ids = ["snap-nbp3xy1d", "snap-nvzu3dmh"] + snapshot_ids = ["snap-8f2updnb"] force_poweroff = true image_description = "create image with snapshot" }` @@ -145,7 +145,7 @@ const ( testAccImageWithSnapShotUpdate = ` resource "tencentcloud_image" "image_snap" { image_name = "image-snapshot-update-keep" - snapshot_ids = ["snap-nbp3xy1d", "snap-nvzu3dmh"] + snapshot_ids = ["snap-8f2updnb"] force_poweroff = false image_description = "update image with snapshot" }` @@ -153,16 +153,16 @@ const ( testAccImageWithInstance = ` resource "tencentcloud_image" "image_instance" { image_name = "image-instance-keep" - instance_id = "ins-2ju245xg" - data_disk_ids = ["disk-gii0vtwi"] + instance_id = "ins-fodds4y2" + data_disk_ids = ["disk-mrnskm5i"] image_description = "create image with instance" }` testAccImageWithInstanceUpdate = ` resource "tencentcloud_image" "image_instance" { image_name = "image-instance-update-keep" - instance_id = "ins-2ju245xg" - data_disk_ids = ["disk-gii0vtwi"] + instance_id = "ins-fodds4y2" + data_disk_ids = ["disk-mrnskm5i"] image_description = "update image with instance" }` ) From 1a189b33eade75da2adbea1ca81e189aa7c865f1 Mon Sep 17 00:00:00 2001 From: mikatong Date: Mon, 14 Mar 2022 21:05:00 +0800 Subject: [PATCH 2/3] fix: cvm unit test --- tencentcloud/resource_tc_instance.go | 4 ++-- tencentcloud/resource_tc_instance_test.go | 8 ++------ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/tencentcloud/resource_tc_instance.go b/tencentcloud/resource_tc_instance.go index 8096a3877d..8dc9d59c5c 100644 --- a/tencentcloud/resource_tc_instance.go +++ b/tencentcloud/resource_tc_instance.go @@ -1390,8 +1390,8 @@ func resourceTencentCloudInstanceUpdate(d *schema.ResourceData, meta interface{} } // Modifying instance type need restart the instance // so status of CVM must be running when running flag is true - if instance != nil && instance.LatestOperationState != nil && (*instance.LatestOperationState == CVM_LATEST_OPERATION_STATE_OPERATING || - (flag && *instance.InstanceState != CVM_STATUS_RUNNING)) { + if instance != nil && (instance.LatestOperationState != nil && *instance.LatestOperationState == CVM_LATEST_OPERATION_STATE_OPERATING || + (flag && instance.LatestOperationState != nil && *instance.InstanceState != CVM_STATUS_RUNNING)) { return resource.RetryableError(fmt.Errorf("cvm instance latest operetion status is %s, retry...", *instance.LatestOperationState)) } return nil diff --git a/tencentcloud/resource_tc_instance_test.go b/tencentcloud/resource_tc_instance_test.go index 2511f1045b..d31e445b9c 100644 --- a/tencentcloud/resource_tc_instance_test.go +++ b/tencentcloud/resource_tc_instance_test.go @@ -263,7 +263,7 @@ func TestAccTencentCloudInstanceWithImageLogin(t *testing.T) { id := "tencentcloud_instance.foo" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_PREPAY) }, IDRefreshName: id, Providers: testAccProviders, CheckDestroy: testAccCheckInstanceDestroy, @@ -473,7 +473,7 @@ func TestAccTencentCloudInstanceWithPrepaidChargeType(t *testing.T) { id := "tencentcloud_instance.foo" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_PREPAY) }, IDRefreshName: id, Providers: testAccProviders, CheckDestroy: testAccCheckInstanceDestroy, @@ -665,7 +665,6 @@ resource "tencentcloud_instance" "foo" { availability_zone = data.tencentcloud_availability_zones.default.zones.0.name image_id = data.tencentcloud_images.default.images.0.image_id instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type - internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR" allocate_public_ip = %s system_disk_type = "CLOUD_PREMIUM" } @@ -682,7 +681,6 @@ resource "tencentcloud_instance" "foo" { availability_zone = data.tencentcloud_availability_zones.default.zones.0.name image_id = data.tencentcloud_images.default.images.0.image_id instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type - internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR" internet_max_bandwidth_out = %d allocate_public_ip = %s system_disk_type = "CLOUD_PREMIUM" @@ -757,7 +755,6 @@ resource "tencentcloud_instance" "foo" { availability_zone = data.tencentcloud_availability_zones.default.zones.0.name image_id = data.tencentcloud_images.zoo.images.0.image_id instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type - internet_max_bandwidth_out = 1 keep_image_login = true system_disk_type = "CLOUD_PREMIUM" } @@ -872,7 +869,6 @@ resource "tencentcloud_instance" "foo" { availability_zone = data.tencentcloud_availability_zones.default.zones.0.name image_id = data.tencentcloud_images.default.images.0.image_id instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type - hostname = var.instance_name system_disk_type = "CLOUD_PREMIUM" instance_charge_type = "SPOTPAID" spot_instance_type = "ONE-TIME" From 4d4fb9244c68f26fc9db2349956c4e5160096dc4 Mon Sep 17 00:00:00 2001 From: mikatong Date: Tue, 15 Mar 2022 14:50:05 +0800 Subject: [PATCH 3/3] fix: cvm unit test --- tencentcloud/resource_tc_instance_test.go | 66 +---------------------- 1 file changed, 2 insertions(+), 64 deletions(-) diff --git a/tencentcloud/resource_tc_instance_test.go b/tencentcloud/resource_tc_instance_test.go index d31e445b9c..ff9145f611 100644 --- a/tencentcloud/resource_tc_instance_test.go +++ b/tencentcloud/resource_tc_instance_test.go @@ -108,15 +108,13 @@ func TestAccTencentCloudInstanceWithDataDisk(t *testing.T) { testAccCheckTencentCloudDataSourceID(id), testAccCheckTencentCloudInstanceExists(id), resource.TestCheckResourceAttr(id, "instance_status", "RUNNING"), - resource.TestCheckResourceAttr(id, "system_disk_size", "50"), + resource.TestCheckResourceAttr(id, "system_disk_size", "100"), resource.TestCheckResourceAttr(id, "system_disk_type", "CLOUD_PREMIUM"), resource.TestCheckResourceAttr(id, "data_disks.0.data_disk_type", "CLOUD_PREMIUM"), resource.TestCheckResourceAttr(id, "data_disks.0.data_disk_size", "100"), resource.TestCheckResourceAttr(id, "data_disks.0.data_disk_snapshot_id", ""), resource.TestCheckResourceAttr(id, "data_disks.1.data_disk_type", "CLOUD_PREMIUM"), resource.TestCheckResourceAttr(id, "data_disks.1.data_disk_size", "100"), - //TODO: snapshot is pre-paid required - //resource.TestCheckResourceAttr(id, "data_disks.1.data_disk_snapshot_id", "snap-nvzu3dmh"), ), }, { @@ -132,7 +130,6 @@ func TestAccTencentCloudInstanceWithDataDisk(t *testing.T) { resource.TestCheckResourceAttr(id, "data_disks.0.data_disk_snapshot_id", ""), resource.TestCheckResourceAttr(id, "data_disks.1.data_disk_type", "CLOUD_PREMIUM"), resource.TestCheckResourceAttr(id, "data_disks.1.data_disk_size", "150"), - //resource.TestCheckResourceAttr(id, "data_disks.1.data_disk_snapshot_id", "snap-nvzu3dmh"), ), }, }, @@ -467,36 +464,6 @@ func TestAccTencentCloudInstanceWithSpotpaid(t *testing.T) { }) } -/* Skip prepaid for now -func TestAccTencentCloudInstanceWithPrepaidChargeType(t *testing.T) { - t.Parallel() - - id := "tencentcloud_instance.foo" - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_PREPAY) }, - IDRefreshName: id, - Providers: testAccProviders, - CheckDestroy: testAccCheckInstanceDestroy, - Steps: []resource.TestStep{ - { - Config: testAccTencentCloudInstancePrepaidRenew, - Check: resource.ComposeTestCheckFunc( - testAccCheckTencentCloudInstanceExists(id), - resource.TestCheckResourceAttr(id, "instance_charge_type_prepaid_renew_flag", "NOTIFY_AND_AUTO_RENEW"), - ), - }, { - Config: testAccTencentCloudInstancePrepaidRenewUpdate, - Check: resource.ComposeTestCheckFunc( - testAccCheckTencentCloudInstanceExists(id), - resource.TestCheckResourceAttr(id, "instance_charge_type_prepaid_renew_flag", "NOTIFY_AND_MANUAL_RENEW"), - ), - }, - }, - }) -} - -*/ - func testAccCheckTencentCloudInstanceExists(n string) resource.TestCheckFunc { return func(s *terraform.State) error { logId := getLogId(contextNil) @@ -608,6 +575,7 @@ resource "tencentcloud_instance" "foo" { instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type system_disk_type = "CLOUD_PREMIUM" + system_disk_size = 100 data_disks { data_disk_type = "CLOUD_PREMIUM" @@ -875,33 +843,3 @@ resource "tencentcloud_instance" "foo" { spot_max_price = "0.5" } ` - -const testAccTencentCloudInstancePrepaidRenew = defaultInstanceVariable + ` -resource "tencentcloud_instance" "foo" { - instance_name = var.instance_name - availability_zone = data.tencentcloud_availability_zones.default.zones.0.name - image_id = data.tencentcloud_images.default.images.0.image_id - instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type - hostname = var.instance_name - system_disk_type = "CLOUD_PREMIUM" - instance_charge_type = "PREPAID" - instance_charge_type_prepaid_renew_flag = "NOTIFY_AND_AUTO_RENEW" - instance_charge_type_prepaid_period = 1 - force_delete = true -} -` - -const testAccTencentCloudInstancePrepaidRenewUpdate = defaultInstanceVariable + ` -resource "tencentcloud_instance" "foo" { - instance_name = var.instance_name - availability_zone = data.tencentcloud_availability_zones.default.zones.0.name - image_id = data.tencentcloud_images.default.images.0.image_id - instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type - hostname = var.instance_name - system_disk_type = "CLOUD_PREMIUM" - instance_charge_type = "PREPAID" - instance_charge_type_prepaid_renew_flag = "NOTIFY_AND_MANUAL_RENEW" - instance_charge_type_prepaid_period = 1 - force_delete = true -} -`