diff --git a/docs/resources/gaussdb_mysql_instance.md b/docs/resources/gaussdb_mysql_instance.md index 531cc7b2cb..cf0c0ae0d2 100644 --- a/docs/resources/gaussdb_mysql_instance.md +++ b/docs/resources/gaussdb_mysql_instance.md @@ -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. diff --git a/go.mod b/go.mod index a4acbe4275..1274a8b416 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 71a9aa6de5..1adc08a28f 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/huaweicloud/resource_huaweicloud_gaussdb_mysql_instance.go b/huaweicloud/resource_huaweicloud_gaussdb_mysql_instance.go index b4937bc32a..6b298bd348 100644 --- a/huaweicloud/resource_huaweicloud_gaussdb_mysql_instance.go +++ b/huaweicloud/resource_huaweicloud_gaussdb_mysql_instance.go @@ -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, @@ -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 { @@ -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{}{ @@ -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 @@ -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) @@ -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{}) diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/networking/v1/eips/requests.go b/vendor/github.com/huaweicloud/golangsdk/openstack/networking/v1/eips/requests.go index 3f296a96a7..5b7e0857e3 100644 --- a/vendor/github.com/huaweicloud/golangsdk/openstack/networking/v1/eips/requests.go +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/networking/v1/eips/requests.go @@ -2,6 +2,7 @@ package eips import ( "github.com/huaweicloud/golangsdk" + "github.com/huaweicloud/golangsdk/openstack/common/structs" "github.com/huaweicloud/golangsdk/pagination" ) @@ -16,6 +17,9 @@ type ApplyOpts struct { IP PublicIpOpts `json:"publicip" required:"true"` Bandwidth BandwidthOpts `json:"bandwidth" required:"true"` EnterpriseProjectID string `json:"enterprise_project_id,omitempty"` + + //ExtendParam is only valid by v2.0 client + ExtendParam *structs.ChargeInfo `json:"extendParam,omitempty"` } type PublicIpOpts struct { diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/networking/v1/eips/results.go b/vendor/github.com/huaweicloud/golangsdk/openstack/networking/v1/eips/results.go index c0d5b2da49..35ca6c5b7a 100644 --- a/vendor/github.com/huaweicloud/golangsdk/openstack/networking/v1/eips/results.go +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/networking/v1/eips/results.go @@ -11,11 +11,20 @@ type ApplyResult struct { } func (r ApplyResult) Extract() (PublicIp, error) { - var ip struct { - Ip PublicIp `json:"publicip"` + var ipResp struct { + IP PublicIp `json:"publicip"` + OrderID string `json:"order_id"` + PublicipID string `json:"publicip_id"` } - err := r.Result.ExtractInto(&ip) - return ip.Ip, err + err := r.Result.ExtractInto(&ipResp) + if ipResp.PublicipID != "" { + ipResp.IP.ID = ipResp.PublicipID + } + if ipResp.OrderID != "" { + ipResp.IP.OrderID = ipResp.OrderID + } + + return ipResp.IP, err } //PublicIp is a struct that represents a public ip @@ -27,6 +36,7 @@ type PublicIp struct { PrivateAddress string `json:"private_ip_address"` PortID string `json:"port_id"` TenantID string `json:"tenant_id"` + OrderID string `json:"order_id"` CreateTime string `json:"create_time"` BandwidthID string `json:"bandwidth_id"` BandwidthSize int `json:"bandwidth_size"` @@ -40,11 +50,11 @@ type GetResult struct { } func (r GetResult) Extract() (PublicIp, error) { - var Ip struct { - Ip PublicIp `json:"publicip"` + var getResp struct { + IP PublicIp `json:"publicip"` } - err := r.Result.ExtractInto(&Ip) - return Ip.Ip, err + err := r.Result.ExtractInto(&getResp) + return getResp.IP, err } //DeleteResult is a struct of delete result diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/taurusdb/v3/instances/requests.go b/vendor/github.com/huaweicloud/golangsdk/openstack/taurusdb/v3/instances/requests.go index 99d15cb3ad..ee7f432422 100644 --- a/vendor/github.com/huaweicloud/golangsdk/openstack/taurusdb/v3/instances/requests.go +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/taurusdb/v3/instances/requests.go @@ -17,6 +17,10 @@ type ChargeInfoOpt struct { IsAutoPay string `json:"is_auto_pay,omitempty"` } +type VolumeOpt struct { + Size int `json:"size" required:"true"` +} + type DataStoreOpt struct { Type string `json:"type" required:"true"` Version string `json:"version" required:"true"` @@ -46,6 +50,7 @@ type CreateTaurusDBOpts struct { DataStore DataStoreOpt `json:"datastore" required:"true"` BackupStrategy *BackupStrategyOpt `json:"backup_strategy,omitempty"` ChargeInfo *ChargeInfoOpt `json:"charge_info,omitempty"` + Volume *VolumeOpt `json:"volume,omitempty"` } type CreateTaurusDBBuilder interface { @@ -267,6 +272,38 @@ func UpdatePass(client *golangsdk.ServiceClient, instanceId string, opts UpdateP return } +type ExtendVolumeOpts struct { + Size int `json:"size" required:"true"` + IsAutoPay string `json:"is_auto_pay,omitempty"` +} + +type ExtendVolumeBuilder interface { + ToVolumeExtendMap() (map[string]interface{}, error) +} + +func (opts ExtendVolumeOpts) ToVolumeExtendMap() (map[string]interface{}, error) { + b, err := golangsdk.BuildRequestBody(opts, "") + if err != nil { + return nil, err + } + return b, nil +} + +func ExtendVolume(client *golangsdk.ServiceClient, instanceId string, opts ExtendVolumeBuilder) (r ExtendResult) { + b, err := opts.ToVolumeExtendMap() + if err != nil { + r.Err = err + return + } + + _, r.Err = client.Post(volumeURL(client, instanceId), b, &r.Body, &golangsdk.RequestOpts{ + OkCodes: []int{201}, + MoreHeaders: requestOpts.MoreHeaders, + }) + + return +} + type ResizeOpts struct { Spec string `json:"spec_code" required:"true"` } diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/taurusdb/v3/instances/results.go b/vendor/github.com/huaweicloud/golangsdk/openstack/taurusdb/v3/instances/results.go index 1d3fea30af..2fd2570f37 100644 --- a/vendor/github.com/huaweicloud/golangsdk/openstack/taurusdb/v3/instances/results.go +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/taurusdb/v3/instances/results.go @@ -78,16 +78,21 @@ type Volume struct { Used string `json:"used"` } +type NodeVolume struct { + Size int `json:"size"` +} + type Nodes struct { - Id string `json:"id"` - Name string `json:"name"` - Type string `json:"type"` - Status string `json:"status"` - PrivateIps []string `json:"private_read_ips"` - Port int `json:"port"` - Flavor string `json:"flavor_ref"` - Region string `json:"region_code"` - AvailabilityZone string `json:"az_code"` + Id string `json:"id"` + Name string `json:"name"` + Type string `json:"type"` + Status string `json:"status"` + PrivateIps []string `json:"private_read_ips"` + Port int `json:"port"` + Flavor string `json:"flavor_ref"` + Region string `json:"region_code"` + AvailabilityZone string `json:"az_code"` + Volume NodeVolume `json:"volume"` } type commonResult struct { @@ -128,6 +133,10 @@ func (r GetResult) Extract() (*TaurusDBInstance, error) { return &instance, err } +type ExtendResult struct { + golangsdk.ErrResult +} + type ListTaurusDBResult struct { commonResult } diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/taurusdb/v3/instances/urls.go b/vendor/github.com/huaweicloud/golangsdk/openstack/taurusdb/v3/instances/urls.go index 861dce02a3..8eab6268d5 100644 --- a/vendor/github.com/huaweicloud/golangsdk/openstack/taurusdb/v3/instances/urls.go +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/taurusdb/v3/instances/urls.go @@ -34,6 +34,10 @@ func passwordURL(c *golangsdk.ServiceClient, instanceID string) string { return c.ServiceURL("instances", instanceID, "password") } +func volumeURL(c *golangsdk.ServiceClient, instanceID string) string { + return c.ServiceURL("instances", instanceID, "volume/extend") +} + func actionURL(c *golangsdk.ServiceClient, instanceID string) string { return c.ServiceURL("instances", instanceID, "action") } diff --git a/vendor/modules.txt b/vendor/modules.txt index 56c88b8785..da48b686c9 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -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