diff --git a/docs/resources/gaussdb_mysql_proxy.md b/docs/resources/gaussdb_mysql_proxy.md index ffc28e37b8..ccfc5ebdf2 100644 --- a/docs/resources/gaussdb_mysql_proxy.md +++ b/docs/resources/gaussdb_mysql_proxy.md @@ -120,6 +120,10 @@ In addition to all arguments above, the following attributes are exported: * `nodes` - Indicates the node information of the proxy. The [nodes](#nodes_struct) structure is documented below. +* `current_version` - Indicates the current version of the proxy. + +* `can_upgrade` - Indicates whether the proxy can be upgrade. + The `nodes` block supports: diff --git a/huaweicloud/services/acceptance/gaussdb/resource_huaweicloud_gaussdb_mysql_proxy_test.go b/huaweicloud/services/acceptance/gaussdb/resource_huaweicloud_gaussdb_mysql_proxy_test.go index 0806054db9..c3a098ac06 100644 --- a/huaweicloud/services/acceptance/gaussdb/resource_huaweicloud_gaussdb_mysql_proxy_test.go +++ b/huaweicloud/services/acceptance/gaussdb/resource_huaweicloud_gaussdb_mysql_proxy_test.go @@ -102,6 +102,16 @@ func TestAccGaussDBMySQLProxy_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "parameters.0.value", "Loose"), resource.TestCheckResourceAttr(resourceName, "parameters.0.elem_type", "system"), resource.TestCheckResourceAttr(resourceName, "consistence_mode", "session"), + resource.TestCheckResourceAttrSet(resourceName, "address"), + resource.TestCheckResourceAttrSet(resourceName, "current_version"), + resource.TestCheckResourceAttrSet(resourceName, "can_upgrade"), + resource.TestCheckResourceAttrSet(resourceName, "nodes.#"), + resource.TestCheckResourceAttrSet(resourceName, "nodes.0.id"), + resource.TestCheckResourceAttrSet(resourceName, "nodes.0.status"), + resource.TestCheckResourceAttrSet(resourceName, "nodes.0.name"), + resource.TestCheckResourceAttrSet(resourceName, "nodes.0.role"), + resource.TestCheckResourceAttrSet(resourceName, "nodes.0.az_code"), + resource.TestCheckResourceAttrSet(resourceName, "nodes.0.frozen_flag"), ), }, { diff --git a/huaweicloud/services/gaussdb/resource_huaweicloud_gaussdb_mysql_proxy.go b/huaweicloud/services/gaussdb/resource_huaweicloud_gaussdb_mysql_proxy.go index 4b8c0e5f87..e7f579f9d8 100644 --- a/huaweicloud/services/gaussdb/resource_huaweicloud_gaussdb_mysql_proxy.go +++ b/huaweicloud/services/gaussdb/resource_huaweicloud_gaussdb_mysql_proxy.go @@ -35,6 +35,7 @@ import ( // @API GaussDBforMySQL POST /v3/{project_id}/instances/{instance_id}/proxy/transaction-split // @API GaussDBforMySQL PUT /v3/{project_id}/instances/{instance_id}/proxy/{proxy_id}/session-consistence // @API GaussDBforMySQL GET /v3/{project_id}/instances/{instance_id}/proxies +// @API GaussDBforMySQL GET /v3/{project_id}/instances/{instance_id}/proxy/{proxy_id}/{engine_name}/proxy-version // @API GaussDBforMySQL GET /v3/{project_id}/instances/{instance_id}/proxy/{proxy_id}/configurations // @API GaussDBforMySQL DELETE /v3/{project_id}/instances/{instance_id}/proxy func ResourceGaussDBProxy() *schema.Resource { @@ -163,6 +164,14 @@ func ResourceGaussDBProxy() *schema.Resource { Computed: true, Elem: gaussDBMysqlProxyNodeSchema(), }, + "current_version": { + Type: schema.TypeString, + Computed: true, + }, + "can_upgrade": { + Type: schema.TypeBool, + Computed: true, + }, }, } } @@ -380,6 +389,16 @@ func resourceGaussDBProxyRead(_ context.Context, d *schema.ResourceData, meta in mErr = multierror.Append(d.Set("parameters", parameters)) } + version, err := getGaussDBProxyVersion(d, client) + if err != nil { + log.Printf("[WARN] fetching GaussDB MySQL proxy version failed: %s", err) + } else { + mErr = multierror.Append( + d.Set("current_version", utils.PathSearch("current_version", version, nil)), + d.Set("can_upgrade", utils.PathSearch("can_upgrade", version, nil)), + ) + } + return diag.FromErr(mErr.ErrorOrNil()) } @@ -503,6 +522,29 @@ func getGaussDBProxyParameters(d *schema.ResourceData, client *golangsdk.Service return flattenGaussDBProxyParameters(listRespBody, d), nil } +func getGaussDBProxyVersion(d *schema.ResourceData, client *golangsdk.ServiceClient) (interface{}, error) { + var ( + httpUrl = "v3/{project_id}/instances/{instance_id}/proxy/{proxy_id}/{engine_name}/proxy-version" + ) + + getPath := client.Endpoint + httpUrl + getPath = strings.ReplaceAll(getPath, "{project_id}", client.ProjectID) + getPath = strings.ReplaceAll(getPath, "{instance_id}", d.Get("instance_id").(string)) + getPath = strings.ReplaceAll(getPath, "{proxy_id}", d.Id()) + getPath = strings.ReplaceAll(getPath, "{engine_name}", "taurusproxy") + + getOpt := golangsdk.RequestOpts{ + KeepResponseBody: true, + MoreHeaders: map[string]string{"Content-Type": "application/json"}, + } + getResp, err := client.Request("GET", getPath, &getOpt) + if err != nil { + return nil, err + } + + return utils.FlattenResponse(getResp) +} + func flattenGaussDBProxyParameters(resp interface{}, d *schema.ResourceData) []interface{} { if resp == nil { return nil