diff --git a/docs/resources/gaussdb_mysql_proxy.md b/docs/resources/gaussdb_mysql_proxy.md index 72109ed75f..ffc28e37b8 100644 --- a/docs/resources/gaussdb_mysql_proxy.md +++ b/docs/resources/gaussdb_mysql_proxy.md @@ -83,6 +83,13 @@ The following arguments are supported: Defaults to **OFF**. +* `consistence_mode` - (Optional, String) Specifies the consistency mode of the proxy. Value options: + + **session**: session consistency. + + **global**: global consistency. + + **eventual**: eventual consistency. + + Defaults to **eventual**. + The `master_node_weight` and `readonly_nodes_weight` 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 ebb6a3467d..0806054db9 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 @@ -101,6 +101,7 @@ func TestAccGaussDBMySQLProxy_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "parameters.0.name", "multiStatementType"), resource.TestCheckResourceAttr(resourceName, "parameters.0.value", "Loose"), resource.TestCheckResourceAttr(resourceName, "parameters.0.elem_type", "system"), + resource.TestCheckResourceAttr(resourceName, "consistence_mode", "session"), ), }, { @@ -125,6 +126,7 @@ func TestAccGaussDBMySQLProxy_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "parameters.0.name", "looseImciApThreshold"), resource.TestCheckResourceAttr(resourceName, "parameters.0.value", "6000"), resource.TestCheckResourceAttr(resourceName, "parameters.0.elem_type", "system"), + resource.TestCheckResourceAttr(resourceName, "consistence_mode", "eventual"), ), }, { @@ -201,6 +203,7 @@ resource "huaweicloud_gaussdb_mysql_proxy" "test" { new_node_weight = 20 port = 3339 transaction_split = "ON" + consistence_mode = "session" master_node_weight { id = local.sort_nodes[0].id @@ -237,6 +240,7 @@ resource "huaweicloud_gaussdb_mysql_proxy" "test" { new_node_weight = 20 port = 3338 transaction_split = "OFF" + consistence_mode = "eventual" master_node_weight { id = local.sort_nodes[0].id @@ -278,6 +282,7 @@ resource "huaweicloud_gaussdb_mysql_proxy" "test" { new_node_weight = 20 port = 3338 transaction_split = "OFF" + consistence_mode = "eventual" master_node_weight { id = local.sort_nodes[0].id diff --git a/huaweicloud/services/gaussdb/resource_huaweicloud_gaussdb_mysql_proxy.go b/huaweicloud/services/gaussdb/resource_huaweicloud_gaussdb_mysql_proxy.go index 05dba83049..4b8c0e5f87 100644 --- a/huaweicloud/services/gaussdb/resource_huaweicloud_gaussdb_mysql_proxy.go +++ b/huaweicloud/services/gaussdb/resource_huaweicloud_gaussdb_mysql_proxy.go @@ -33,6 +33,7 @@ import ( // @API GaussDBforMySQL PUT /v3/{project_id}/instances/{instance_id}/proxy/{proxy_id}/weight // @API GaussDBforMySQL POST /v3/{project_id}/instances/{instance_id}/proxy/{proxy_id}/new-node-auto-add // @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}/configurations // @API GaussDBforMySQL DELETE /v3/{project_id}/instances/{instance_id}/proxy @@ -148,6 +149,11 @@ func ResourceGaussDBProxy() *schema.Resource { Optional: true, Computed: true, }, + "consistence_mode": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, "address": { Type: schema.TypeString, Computed: true, @@ -278,6 +284,13 @@ func resourceGaussDBProxyCreate(ctx context.Context, d *schema.ResourceData, met } } + if consistenceMode, ok := d.GetOk("consistence_mode"); ok && consistenceMode != "eventual" { + err = updateGaussDBMySQLConsistenceMode(ctx, d, client) + if err != nil { + return diag.FromErr(err) + } + } + return resourceGaussDBProxyRead(ctx, d, meta) } @@ -349,6 +362,7 @@ func resourceGaussDBProxyRead(_ context.Context, d *schema.ResourceData, meta in d.Set("readonly_nodes_weight", flattenGaussDBProxyResponseBodyReadonlyNodesWeight(proxy, d)), d.Set("new_node_auto_add_status", utils.PathSearch("proxy.new_node_auto_add_status", proxy, nil)), d.Set("port", utils.PathSearch("proxy.port", proxy, nil)), + d.Set("consistence_mode", utils.PathSearch("proxy.consistence_mode", proxy, nil)), d.Set("address", utils.PathSearch("proxy.address", proxy, nil)), d.Set("nodes", flattenGaussDBProxyResponseBodyNodes(proxy)), ) @@ -590,6 +604,13 @@ func resourceGaussDBProxyUpdate(ctx context.Context, d *schema.ResourceData, met } } + if d.HasChange("consistence_mode") { + err = updateGaussDBMySQLConsistenceMode(ctx, d, client) + if err != nil { + return diag.FromErr(err) + } + } + return resourceGaussDBProxyRead(ctx, d, meta) } @@ -994,6 +1015,56 @@ func buildUpdateGaussDBMySQLTransactionSplitBodyParams(d *schema.ResourceData) m return bodyParams } +func updateGaussDBMySQLConsistenceMode(ctx context.Context, d *schema.ResourceData, client *golangsdk.ServiceClient) error { + var ( + httpUrl = "v3/{project_id}/instances/{instance_id}/proxy/{proxy_id}/session-consistence" + ) + updatePath := client.Endpoint + httpUrl + updatePath = strings.ReplaceAll(updatePath, "{project_id}", client.ProjectID) + updatePath = strings.ReplaceAll(updatePath, "{instance_id}", d.Get("instance_id").(string)) + updatePath = strings.ReplaceAll(updatePath, "{proxy_id}", d.Id()) + + updateOpt := golangsdk.RequestOpts{ + KeepResponseBody: true, + } + updateOpt.JSONBody = buildUpdateGaussDBMySQLConsistenceModeBodyParams(d) + + updateResp, err := client.Request("PUT", updatePath, &updateOpt) + if err != nil { + return fmt.Errorf("error updating GaussDB MySQL proxy consistence mode: %s", err) + } + + updateRespBody, err := utils.FlattenResponse(updateResp) + if err != nil { + return err + } + + jobId := utils.PathSearch("job_id", updateRespBody, nil) + if jobId == nil { + return fmt.Errorf("error updating GaussDB MySQL proxy consistence mode: job_id is not found in API response") + } + + err = checkGaussDBMySQLProxyJobFinish(ctx, client, jobId.(string), d.Timeout(schema.TimeoutUpdate)) + if err != nil { + return err + } + + return nil +} + +func buildUpdateGaussDBMySQLConsistenceModeBodyParams(d *schema.ResourceData) map[string]interface{} { + consistenceMode := d.Get("consistence_mode").(string) + bodyParams := map[string]interface{}{ + "consistence_mode": consistenceMode, + } + if consistenceMode == "session" { + bodyParams["session_consistence"] = true + } else { + bodyParams["session_consistence"] = false + } + return bodyParams +} + func resourceGaussDBProxyDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cfg := meta.(*config.Config) region := cfg.GetRegion(d)