Skip to content

fix(cvm): [118694444]system disk resize online #2740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 24, 2024
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
3 changes: 3 additions & 0 deletions .changelog/2740.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_instance: add param `system_disk_resize_online`
```
8 changes: 8 additions & 0 deletions tencentcloud/services/cvm/resource_tc_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ func ResourceTencentCloudInstance() *schema.Resource {
Computed: true,
Description: "System disk snapshot ID used to initialize the system disk. When system disk type is `LOCAL_BASIC` and `LOCAL_SSD`, disk id is not supported.",
},
"system_disk_resize_online": {
Type: schema.TypeBool,
Optional: true,
Description: "Resize online.",
},
"data_disks": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -1308,6 +1313,9 @@ func resourceTencentCloudInstanceUpdate(d *schema.ResourceData, meta interface{}
DiskSize: helper.IntInt64(size),
DiskType: &diskType,
}
if v, ok := d.GetOkExists("system_disk_resize_online"); ok {
req.ResizeOnline = helper.Bool(v.(bool))
}

err := cvmService.ResizeInstanceDisks(ctx, req)
if err != nil {
Expand Down
135 changes: 135 additions & 0 deletions tencentcloud/services/cvm/resource_tc_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,141 @@ resource "tencentcloud_instance" "cvm_basic" {

`

func TestAccTencentCloudInstance_SystemDiskResizeOnline(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() {
acctest.AccPreCheck(t)
},
Providers: acctest.AccProviders,
CheckDestroy: testAccCheckCvmInstanceDestroy,
Steps: []resource.TestStep{
{
Config: testAccCvmInstanceResource_SystemDiskResizeOnline,
Check: resource.ComposeTestCheckFunc(
testAccCheckCvmInstanceExists("tencentcloud_instance.cvm_system_disk_resize_online"),
resource.TestCheckResourceAttr("tencentcloud_instance.cvm_system_disk_resize_online", "system_disk_type", "CLOUD_PREMIUM"),
resource.TestCheckResourceAttr("tencentcloud_instance.cvm_system_disk_resize_online", "system_disk_size", "100"),
resource.TestCheckResourceAttr("tencentcloud_instance.cvm_system_disk_resize_online", "instance_status", "RUNNING"),
),
},
{
Config: testAccCvmInstanceResource_SystemDiskResizeOnlineUpdate,
Check: resource.ComposeTestCheckFunc(
testAccCheckCvmInstanceExists("tencentcloud_instance.cvm_system_disk_resize_online"),
resource.TestCheckResourceAttr("tencentcloud_instance.cvm_system_disk_resize_online", "system_disk_type", "CLOUD_PREMIUM"),
resource.TestCheckResourceAttr("tencentcloud_instance.cvm_system_disk_resize_online", "system_disk_size", "200"),
resource.TestCheckResourceAttr("tencentcloud_instance.cvm_system_disk_resize_online", "instance_status", "RUNNING"),
),
},
},
})
}

const testAccCvmInstanceResource_SystemDiskResizeOnline = `

data "tencentcloud_availability_zones" "default" {
}
data "tencentcloud_images" "default" {
image_type = ["PUBLIC_IMAGE"]
image_name_regex = "Final"
}
data "tencentcloud_images" "testing" {
image_type = ["PUBLIC_IMAGE"]
}
data "tencentcloud_instance_types" "default" {
memory_size = 2
exclude_sold_out = true

filter {
name = "instance-family"
values = ["S1","S2","S3","S4","S5"]
}
filter {
name = "zone"
values = ["ap-guangzhou-7"]
}
cpu_core_count = 2
}
resource "tencentcloud_vpc" "vpc" {
name = "cvm-resize-online-vpc"
cidr_block = "10.0.0.0/16"
}
resource "tencentcloud_subnet" "subnet" {
availability_zone = "ap-guangzhou-7"
vpc_id = tencentcloud_vpc.vpc.id
name = "cvm-resize-online-subnet"
cidr_block = "10.0.0.0/16"
}
resource "tencentcloud_instance" "cvm_system_disk_resize_online" {
instance_name = "tf-system-disk-resize-online"
availability_zone = "ap-guangzhou-7"
image_id = data.tencentcloud_images.default.images.0.image_id
vpc_id = tencentcloud_vpc.vpc.id

lifecycle {
ignore_changes = [instance_type]
}
instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type
subnet_id = tencentcloud_subnet.subnet.id
system_disk_type = "CLOUD_PREMIUM"
system_disk_size = 100
project_id = 0
}
`

const testAccCvmInstanceResource_SystemDiskResizeOnlineUpdate = `
data "tencentcloud_availability_zones" "default" {
}
data "tencentcloud_images" "default" {
image_type = ["PUBLIC_IMAGE"]
image_name_regex = "Final"
}
data "tencentcloud_images" "testing" {
image_type = ["PUBLIC_IMAGE"]
}
data "tencentcloud_instance_types" "default" {
memory_size = 2
exclude_sold_out = true

filter {
name = "instance-family"
values = ["S1","S2","S3","S4","S5"]
}
filter {
name = "zone"
values = ["ap-guangzhou-7"]
}
cpu_core_count = 2
}
resource "tencentcloud_vpc" "vpc" {
name = "cvm-resize-online-vpc"
cidr_block = "10.0.0.0/16"
}
resource "tencentcloud_subnet" "subnet" {
availability_zone = "ap-guangzhou-7"
vpc_id = tencentcloud_vpc.vpc.id
name = "cvm-resize-online-subnet"
cidr_block = "10.0.0.0/16"
}
resource "tencentcloud_instance" "cvm_system_disk_resize_online" {
instance_name = "tf-system-disk-resize-online"
availability_zone = "ap-guangzhou-7"
image_id = data.tencentcloud_images.default.images.0.image_id
vpc_id = tencentcloud_vpc.vpc.id

lifecycle {
ignore_changes = [instance_type]
}
instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type
subnet_id = tencentcloud_subnet.subnet.id
system_disk_type = "CLOUD_PREMIUM"
system_disk_size = 200
system_disk_resize_online = true
project_id = 0
}
`

func TestAccTencentCloudInstanceResourcePrepaid(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ The following arguments are supported:
* `stopped_mode` - (Optional, String) Billing method of a pay-as-you-go instance after shutdown. Available values: `KEEP_CHARGING`,`STOP_CHARGING`. Default `KEEP_CHARGING`.
* `subnet_id` - (Optional, String) The ID of a VPC subnet. If you want to create instances in a VPC network, this parameter must be set.
* `system_disk_id` - (Optional, String) System disk snapshot ID used to initialize the system disk. When system disk type is `LOCAL_BASIC` and `LOCAL_SSD`, disk id is not supported.
* `system_disk_resize_online` - (Optional, Bool) Resize online.
* `system_disk_size` - (Optional, Int) Size of the system disk. unit is GB, Default is 50GB. If modified, the instance may force stop.
* `system_disk_type` - (Optional, String) System disk type. For more information on limits of system disk types, see [Storage Overview](https://intl.cloud.tencent.com/document/product/213/4952). Valid values: `LOCAL_BASIC`: local disk, `LOCAL_SSD`: local SSD disk, `CLOUD_BASIC`: cloud disk, `CLOUD_SSD`: cloud SSD disk, `CLOUD_PREMIUM`: Premium Cloud Storage, `CLOUD_BSSD`: Basic SSD, `CLOUD_HSSD`: Enhanced SSD, `CLOUD_TSSD`: Tremendous SSD. NOTE: If modified, the instance may force stop.
* `tags` - (Optional, Map) A mapping of tags to assign to the resource. For tag limits, please refer to [Use Limits](https://intl.cloud.tencent.com/document/product/651/13354).
Expand Down
Loading