Skip to content
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

add compute_instace extend system disk support #527

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
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