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 volume extending support #176

Merged
merged 1 commit into from
Aug 2, 2019
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/hashicorp/errwrap v1.0.0
github.com/hashicorp/go-cleanhttp v0.5.0
github.com/hashicorp/terraform v0.12.0
github.com/huaweicloud/golangsdk v0.0.0-20190717062841-42e152cba796
github.com/huaweicloud/golangsdk v0.0.0-20190801094550-c3228f9b10d6
github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a
github.com/mitchellh/go-homedir v1.0.0
github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ github.com/hashicorp/vault v0.10.4/go.mod h1:KfSyffbKxoVyspOdlaGVjIuwLobi07qD1bA
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb h1:b5rjCoWHc7eqmAS4/qyk21ZsHyb6Mxv/jykxvNTkU4M=
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/huaweicloud/golangsdk v0.0.0-20190717062841-42e152cba796 h1:CmcRpTPOWMNOw5UcMMDkEdlHDxCn5KdoYRBLR59XjQk=
github.com/huaweicloud/golangsdk v0.0.0-20190717062841-42e152cba796/go.mod h1:WQBcHRNX9shz3928lWEvstQJtAtYI7ks6XlgtRT9Tcw=
github.com/huaweicloud/golangsdk v0.0.0-20190801094550-c3228f9b10d6 h1:4ys1PB6+nv2Tm2bN8o0COXV8t4QU/GsM4X7VdWdnrHI=
github.com/huaweicloud/golangsdk v0.0.0-20190801094550-c3228f9b10d6/go.mod h1:WQBcHRNX9shz3928lWEvstQJtAtYI7ks6XlgtRT9Tcw=
github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU=
github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a h1:FyS/ubzBR5xJlnJGRTwe7GUHpJOR4ukYK3y+LFNffuA=
github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a/go.mod h1:uoIMjNxUfXi48Ci40IXkPRbghZ1vbti6v9LCbNqRgHY=
Expand Down
28 changes: 27 additions & 1 deletion huaweicloud/resource_huaweicloud_blockstorage_volume_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
"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/compute/v2/extensions/volumeattach"
)
Expand Down Expand Up @@ -40,7 +41,6 @@ func resourceBlockStorageVolumeV2() *schema.Resource {
"size": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
},
"name": {
Type: schema.TypeString,
Expand Down Expand Up @@ -247,6 +247,32 @@ func resourceBlockStorageVolumeV2Update(d *schema.ResourceData, meta interface{}
updateOpts.Metadata = resourceVolumeMetadataV2(d)
}

if d.HasChange("size") {
extendOpts := volumeactions.ExtendSizeOpts{
NewSize: d.Get("size").(int),
}

err = volumeactions.ExtendSize(blockStorageClient, d.Id(), extendOpts).ExtractErr()
if err != nil {
return fmt.Errorf("Error extending huaweicloud_blockstorage_volume_v2 %s size: %s", d.Id(), err)
}

stateConf := &resource.StateChangeConf{
Pending: []string{"extending"},
Target: []string{"available", "in-use"},
Refresh: VolumeV2StateRefreshFunc(blockStorageClient, d.Id()),
Timeout: d.Timeout(schema.TimeoutCreate),
Delay: 10 * time.Second,
MinTimeout: 3 * time.Second,
}

_, err := stateConf.WaitForState()
if err != nil {
return fmt.Errorf(
"Error waiting for huaweicloud_blockstorage_volume_v2 %s to become ready: %s", d.Id(), err)
}
}

_, err = volumes.Update(blockStorageClient, d.Id(), updateOpts).Extract()
if err != nil {
return fmt.Errorf("Error updating HuaweiCloud volume: %s", err)
Expand Down
76 changes: 75 additions & 1 deletion huaweicloud/resource_huaweicloud_blockstorage_volume_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ func TestAccBlockStorageV2Volume_basic(t *testing.T) {
testAccCheckBlockStorageV2VolumeMetadata(&volume, "foo", "bar"),
resource.TestCheckResourceAttr(
"huaweicloud_blockstorage_volume_v2.volume_1", "name", "volume_1"),
resource.TestCheckResourceAttr(
"huaweicloud_blockstorage_volume_v2.volume_1", "size", "1"),
),
},
{
Expand All @@ -35,6 +37,32 @@ func TestAccBlockStorageV2Volume_basic(t *testing.T) {
testAccCheckBlockStorageV2VolumeMetadata(&volume, "foo", "bar"),
resource.TestCheckResourceAttr(
"huaweicloud_blockstorage_volume_v2.volume_1", "name", "volume_1-updated"),
resource.TestCheckResourceAttr(
"huaweicloud_blockstorage_volume_v2.volume_1", "size", "2"),
),
},
},
})
}

func TestAccBlockStorageV2Volume_online_resize(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckBlockStorageV2VolumeDestroy,
Steps: []resource.TestStep{
{
Config: testAccBlockStorageV2Volume_online_resize,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"huaweicloud_blockstorage_volume_v2.volume_1", "size", "1"),
),
},
{
Config: testAccBlockStorageV2Volume_online_resize_update,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"huaweicloud_blockstorage_volume_v2.volume_1", "size", "2"),
),
},
},
Expand Down Expand Up @@ -193,7 +221,7 @@ resource "huaweicloud_blockstorage_volume_v2" "volume_1" {
metadata = {
foo = "bar"
}
size = 1
size = 2
}
`

Expand All @@ -218,3 +246,49 @@ resource "huaweicloud_blockstorage_volume_v2" "volume_1" {
}
}
`

var testAccBlockStorageV2Volume_online_resize = fmt.Sprintf(`
resource "huaweicloud_compute_instance_v2" "basic" {
name = "instance_1"
security_groups = ["default"]
availability_zone = "%s"
network {
uuid = "%s"
}
}

resource "huaweicloud_blockstorage_volume_v2" "volume_1" {
name = "volume_1"
description = "test volume"
availability_zone = "%s"
size = 1
}

resource "huaweicloud_compute_volume_attach_v2" "va_1" {
instance_id = "${huaweicloud_compute_instance_v2.basic.id}"
volume_id = "${huaweicloud_blockstorage_volume_v2.volume_1.id}"
}
`, OS_AVAILABILITY_ZONE, OS_NETWORK_ID, OS_AVAILABILITY_ZONE)

var testAccBlockStorageV2Volume_online_resize_update = fmt.Sprintf(`
resource "huaweicloud_compute_instance_v2" "basic" {
name = "instance_1"
security_groups = ["default"]
availability_zone = "%s"
network {
uuid = "%s"
}
}

resource "huaweicloud_blockstorage_volume_v2" "volume_1" {
name = "volume_1"
description = "test volume"
availability_zone = "%s"
size = 2
}

resource "huaweicloud_compute_volume_attach_v2" "va_1" {
instance_id = "${huaweicloud_compute_instance_v2.basic.id}"
volume_id = "${huaweicloud_blockstorage_volume_v2.volume_1.id}"
}
`, OS_AVAILABILITY_ZONE, OS_NETWORK_ID, OS_AVAILABILITY_ZONE)

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading