Skip to content

Commit

Permalink
add compute_instace extend system disk support
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason-Zhang9309 committed Sep 15, 2020
1 parent 81ccb45 commit 2dd2567
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
36 changes: 35 additions & 1 deletion huaweicloud/resource_huaweicloud_compute_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"},
},
Expand Down Expand Up @@ -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)
}

Expand Down
4 changes: 3 additions & 1 deletion website/docs/r/compute_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2dd2567

Please sign in to comment.