Skip to content

Commit

Permalink
Add extend-volume support for gaussdb_cassandra (#444)
Browse files Browse the repository at this point in the history
  • Loading branch information
niuzhenguo authored Aug 17, 2020
1 parent af49da6 commit f54bc43
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 8 deletions.
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.1
github.com/hashicorp/terraform-plugin-sdk v1.13.0
github.com/huaweicloud/golangsdk v0.0.0-20200813075425-67f9b02929b1
github.com/huaweicloud/golangsdk v0.0.0-20200814025358-107091b04d02
github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a
github.com/mitchellh/go-homedir v1.1.0
github.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb h1:b5rjCoWHc7eqmAS
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1vq2e6IsrXKrZit1bv/TDYFGMp4BQ=
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
github.com/huaweicloud/golangsdk v0.0.0-20200813064719-df5ea4d1b7dd h1:6WF4zOzKpUJz3MRuZa7w1PGO4Yoxn60ymPYCtcVRCvU=
github.com/huaweicloud/golangsdk v0.0.0-20200813064719-df5ea4d1b7dd/go.mod h1:WQBcHRNX9shz3928lWEvstQJtAtYI7ks6XlgtRT9Tcw=
github.com/huaweicloud/golangsdk v0.0.0-20200814025358-107091b04d02 h1:220kPi7rioom5W8nK0Hy5OeqiERASRsStA4AsSNcBx0=
github.com/huaweicloud/golangsdk v0.0.0-20200814025358-107091b04d02/go.mod h1:WQBcHRNX9shz3928lWEvstQJtAtYI7ks6XlgtRT9Tcw=
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=
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
Expand Down
56 changes: 52 additions & 4 deletions huaweicloud/resource_huaweicloud_gaussdb_cassandra_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func resourceGeminiDBInstanceV3() *schema.Resource {
"volume_size": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
ForceNew: false,
},
"password": {
Type: schema.TypeString,
Expand Down Expand Up @@ -447,10 +447,58 @@ func resourceGeminiDBInstanceV3Update(d *schema.ResourceData, meta interface{})
return fmt.Errorf("Error creating Huaweicloud Vpc: %s", err)
}
//update tags
tagErr := UpdateResourceTags(client, d, "instances")
if tagErr != nil {
return fmt.Errorf("Error updating tags of GeminiDB %q: %s", d.Id(), tagErr)
if d.HasChange("tags") {
tagErr := UpdateResourceTags(client, d, "instances")
if tagErr != nil {
return fmt.Errorf("Error updating tags of GeminiDB %q: %s", d.Id(), tagErr)
}
}

if d.HasChange("volume_size") {
extendOpts := instances.ExtendVolumeOpts{
Size: d.Get("volume_size").(int),
}

result := instances.ExtendVolume(client, d.Id(), extendOpts)
if result.Err != nil {
return fmt.Errorf("Error extending huaweicloud_gaussdb_cassandra_instance %s size: %s", d.Id(), err)
}

stateConf := &resource.StateChangeConf{
Pending: []string{"extending"},
Target: []string{"available"},
Refresh: GeminiDBInstanceExtendVolumeRefreshFunc(client, d.Id()),
Timeout: d.Timeout(schema.TimeoutCreate),
Delay: 15 * time.Second,
MinTimeout: 10 * time.Second,
}

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

return resourceGeminiDBInstanceV3Read(d, meta)
}

func GeminiDBInstanceExtendVolumeRefreshFunc(client *golangsdk.ServiceClient, instanceID string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
instance, err := instances.GetInstanceByID(client, instanceID)

if err != nil {
return nil, "", err
}
if instance.Id == "" {
return instance, "deleted", nil
}
for _, action := range instance.Actions {
if action == "RESIZE_VOLUME" {
return instance, "extending", nil
}
}

return instance, "available", nil
}
}

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

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

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

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ github.com/hashicorp/terraform-svchost/auth
github.com/hashicorp/terraform-svchost/disco
# github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d
github.com/hashicorp/yamux
# github.com/huaweicloud/golangsdk v0.0.0-20200813075425-67f9b02929b1
# github.com/huaweicloud/golangsdk v0.0.0-20200814025358-107091b04d02
## explicit
github.com/huaweicloud/golangsdk
github.com/huaweicloud/golangsdk/internal
Expand Down

0 comments on commit f54bc43

Please sign in to comment.