Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tencentcloud/data_source_tc_reserved_instances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
{
Expand All @@ -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"
}
`
22 changes: 11 additions & 11 deletions tencentcloud/resource_tc_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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"),
),
Expand All @@ -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"),
),
Expand All @@ -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"),
),
Expand All @@ -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"),
),
Expand Down Expand Up @@ -137,32 +137,32 @@ 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"
}`

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"
}`

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"
}`
)
4 changes: 2 additions & 2 deletions tencentcloud/resource_tc_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
72 changes: 3 additions & 69 deletions tencentcloud/resource_tc_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
{
Expand All @@ -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"),
),
},
},
Expand Down Expand Up @@ -263,7 +260,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,
Expand Down Expand Up @@ -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() { testAccPreCheck(t) },
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)
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -665,7 +633,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"
}
Expand All @@ -682,7 +649,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"
Expand Down Expand Up @@ -757,7 +723,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"
}
Expand Down Expand Up @@ -872,40 +837,9 @@ 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"
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
}
`