diff --git a/huaweicloud/resource_huaweicloud_compute_instance.go b/huaweicloud/resource_huaweicloud_compute_instance.go index 753c2d1e49..3419f90b8c 100644 --- a/huaweicloud/resource_huaweicloud_compute_instance.go +++ b/huaweicloud/resource_huaweicloud_compute_instance.go @@ -14,6 +14,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/huaweicloud/golangsdk" + "github.com/huaweicloud/golangsdk/openstack/blockstorage/extensions/volumeactions" "github.com/huaweicloud/golangsdk/openstack/blockstorage/v2/volumes" "github.com/huaweicloud/golangsdk/openstack/common/tags" "github.com/huaweicloud/golangsdk/openstack/compute/v2/extensions/availabilityzones" @@ -254,7 +255,6 @@ func resourceComputeInstanceV2() *schema.Resource { "system_disk_size": { Type: schema.TypeInt, Optional: true, - ForceNew: true, Computed: true, ConflictsWith: []string{"block_device", "metadata"}, }, @@ -961,6 +961,40 @@ func resourceComputeInstanceV2Update(d *schema.ResourceData, meta interface{}) e } } + if d.HasChange("system_disk_size") { + extendOpts := volumeactions.ExtendSizeOpts{ + NewSize: d.Get("system_disk_size").(int), + } + + blockStorageClient, err := config.blockStorageV2Client(GetRegion(d, config)) + + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud block storage client: %s", err) + } + + systemDiskID := d.Get("system_disk_id").(string) + + err = volumeactions.ExtendSize(blockStorageClient, systemDiskID, extendOpts).ExtractErr() + if err != nil { + return fmt.Errorf("Error extending huaweicloud_compute_instance system disk %s size: %s", systemDiskID, err) + } + + stateConf := &resource.StateChangeConf{ + Pending: []string{"extending"}, + Target: []string{"available", "in-use"}, + Refresh: VolumeV2StateRefreshFunc(blockStorageClient, systemDiskID), + Timeout: d.Timeout(schema.TimeoutUpdate), + Delay: 10 * time.Second, + MinTimeout: 3 * time.Second, + } + + _, err = stateConf.WaitForState() + if err != nil { + return fmt.Errorf( + "Error waiting for huaweicloud_compute_instance system disk %s to become ready: %s", systemDiskID, err) + } + } + return resourceComputeInstanceV2Read(d, meta) } diff --git a/website/docs/r/compute_instance.html.markdown b/website/docs/r/compute_instance.html.markdown index 632f0f0522..e86c56829d 100644 --- a/website/docs/r/compute_instance.html.markdown +++ b/website/docs/r/compute_instance.html.markdown @@ -229,7 +229,9 @@ The following arguments are supported: * `co-p1`: high I/O(performance-optimized) disk type. * `uh-l1`: ultra-high I/O(latency-optimized) disk type. -* `system_disk_size` - (Optional) The system disk size in GB, The value range is 1 to 1024. Changing this creates a new server. +* `system_disk_size` - (Optional) The system disk size in GB, The value range is 1 to 1024. Changing this parameter will update the disk. + You can extend the disk by setting this parameter to a new value, which must be between current size and the max size(1024). + Shrinking the disk is not supported. * `data_disks` - (Optional) An array of one or more data disks to attach to the instance. The data_disks object structure is documented below. Changing this