Skip to content

Commit

Permalink
Add volume_size support for gaussdb mysql (#1201)
Browse files Browse the repository at this point in the history
This adds support for specifying/updating volume size of prePaid
gaussdb mysql instance.
  • Loading branch information
niuzhenguo authored Jun 8, 2021
1 parent 8791ac8 commit cccfa23
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 23 deletions.
3 changes: 3 additions & 0 deletions docs/resources/gaussdb_mysql_instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ The following arguments are supported:

* `force_import` - (Optional, Bool) If specified, try to import the instance instead of creating if the name already existed.

* `volume_size` - (Optional, Int) Specifies the volume size of the instance. The new storage space must be greater than
the current storage and must be a multiple of 10 GB. Only valid when in prePaid mode.

* `charging_mode` - (Optional, String, ForceNew) The charging mode of the instance.
Valid values are *prePaid* and *postPaid*, defaults to *postPaid*.
Changing this creates a new resource.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/hashicorp/errwrap v1.0.0
github.com/hashicorp/go-multierror v1.0.0
github.com/hashicorp/terraform-plugin-sdk v1.16.0
github.com/huaweicloud/golangsdk v0.0.0-20210602080359-3d6e5cdfc40f
github.com/huaweicloud/golangsdk v0.0.0-20210608085437-ebb866377c9f
github.com/jen20/awspolicyequivalence v1.1.0
github.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa // indirect
github.com/stretchr/testify v1.4.0
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,8 @@ github.com/hashicorp/terraform-svchost v0.0.0-20191011084731-65d371908596/go.mod
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-20210528023633-c90ae4249a71 h1:o2s9CcW277XbOQp0EolTCWHrNdBUHCjuu0aKtAedF/k=
github.com/huaweicloud/golangsdk v0.0.0-20210528023633-c90ae4249a71/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0=
github.com/huaweicloud/golangsdk v0.0.0-20210602080359-3d6e5cdfc40f h1:7FSmwn+mnDmezxuOjfDotwmyxQCQOU1waZDLORl7kGc=
github.com/huaweicloud/golangsdk v0.0.0-20210602080359-3d6e5cdfc40f/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0=
github.com/huaweicloud/golangsdk v0.0.0-20210608085437-ebb866377c9f h1:uvvd7F4iujOwAP0E0W7H91IrgBt5KI0xE7A6HCwGTj0=
github.com/huaweicloud/golangsdk v0.0.0-20210608085437-ebb866377c9f/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/imdario/mergo v0.3.9 h1:UauaLniWCFHWd+Jp9oCEkTBj8VO/9DKg3PV3VCNMDIg=
github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
Expand Down
29 changes: 29 additions & 0 deletions huaweicloud/resource_huaweicloud_gaussdb_mysql_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ func resourceGaussDBInstance() *schema.Resource {
Optional: true,
Default: 1,
},
"volume_size": {
Type: schema.TypeInt,
Optional: true,
},
"time_zone": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -308,6 +312,13 @@ func resourceGaussDBInstanceCreate(d *schema.ResourceData, meta interface{}) err
createOpts.MasterAZ = v.(string)
}

if hasFilledOpt(d, "volume_size") {
volume := &instances.VolumeOpt{
Size: d.Get("volume_size").(int),
}
createOpts.Volume = volume
}

// PrePaid
if d.Get("charging_mode") == "prePaid" {
if err := validatePrePaidChargeInfo(d); err != nil {
Expand Down Expand Up @@ -433,6 +444,7 @@ func resourceGaussDBInstanceRead(d *schema.ResourceData, meta interface{}) error
// set nodes
flavor := ""
slave_count := 0
volume_size := 0
nodesList := make([]map[string]interface{}, 0, 1)
for _, raw := range instance.Nodes {
node := map[string]interface{}{
Expand All @@ -445,6 +457,9 @@ func resourceGaussDBInstanceRead(d *schema.ResourceData, meta interface{}) error
if len(raw.PrivateIps) > 0 {
node["private_read_ip"] = raw.PrivateIps[0]
}
if raw.Volume.Size > 0 {
volume_size = raw.Volume.Size
}
nodesList = append(nodesList, node)
if raw.Type == "slave" && raw.Status == "ACTIVE" {
slave_count += 1
Expand All @@ -455,6 +470,7 @@ func resourceGaussDBInstanceRead(d *schema.ResourceData, meta interface{}) error
}
d.Set("nodes", nodesList)
d.Set("read_replicas", slave_count)
d.Set("volume_size", volume_size)
if flavor != "" {
log.Printf("[DEBUG] Node Flavor: %s", flavor)
d.Set("flavor", flavor)
Expand Down Expand Up @@ -589,6 +605,19 @@ func resourceGaussDBInstanceUpdate(d *schema.ResourceData, meta interface{}) err
}
}

if d.HasChange("volume_size") {
extendOpts := instances.ExtendVolumeOpts{
Size: d.Get("volume_size").(int),
IsAutoPay: "true",
}
log.Printf("[DEBUG] Extending Volume: %#v", extendOpts)

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

if d.HasChange("backup_strategy") {
var updateOpts backups.UpdateOpts
backupRaw := d.Get("backup_strategy").([]interface{})
Expand Down

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.

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 @@ -267,7 +267,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-20210602080359-3d6e5cdfc40f
# github.com/huaweicloud/golangsdk v0.0.0-20210608085437-ebb866377c9f
## explicit
github.com/huaweicloud/golangsdk
github.com/huaweicloud/golangsdk/internal
Expand Down

0 comments on commit cccfa23

Please sign in to comment.