From 1516195ebb02e69ceb172d6be500684f02caa4f3 Mon Sep 17 00:00:00 2001 From: "guimin.hgm" Date: Wed, 25 Dec 2024 11:08:03 +0800 Subject: [PATCH] Redis: Improves the invoking redis api method and supports refreshing credential automatically --- alicloud/connectivity/client.go | 5 + .../data_source_alicloud_kvstore_instances.go | 11 +- ...ource_alicloud_kvstore_audit_log_config.go | 15 +- .../resource_alicloud_kvstore_instance.go | 263 ++++++------------ ...resource_alicloud_kvstore_instance_test.go | 18 +- .../resource_alicloud_redis_tair_instance.go | 95 ++----- alicloud/service_alicloud_r_kvstore.go | 107 +------ alicloud/service_alicloud_redis_v2.go | 67 +---- 8 files changed, 140 insertions(+), 441 deletions(-) diff --git a/alicloud/connectivity/client.go b/alicloud/connectivity/client.go index 18f87a8d5d7f..b69528276d02 100644 --- a/alicloud/connectivity/client.go +++ b/alicloud/connectivity/client.go @@ -2322,6 +2322,11 @@ func (client *AliyunClient) WithRKvstoreClient(do func(*r_kvstore.Client) (inter r_kvstoreConn.AppendUserAgent(Module, client.config.ConfigurationSource) r_kvstoreConn.AppendUserAgent(TerraformTraceId, client.config.TerraformTraceId) client.r_kvstoreConn = r_kvstoreConn + } else { + err := client.r_kvstoreConn.InitWithOptions(client.config.RegionId, client.getSdkConfig(), client.config.getAuthCredential(true)) + if err != nil { + return nil, fmt.Errorf("unable to initialize the Redis client: %#v", err) + } } return do(client.r_kvstoreConn) } diff --git a/alicloud/data_source_alicloud_kvstore_instances.go b/alicloud/data_source_alicloud_kvstore_instances.go index 6d31a408cf61..35f0de7bbbf3 100644 --- a/alicloud/data_source_alicloud_kvstore_instances.go +++ b/alicloud/data_source_alicloud_kvstore_instances.go @@ -7,7 +7,6 @@ import ( "time" "github.com/PaesslerAG/jsonpath" - util "github.com/alibabacloud-go/tea-utils/service" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity" @@ -437,17 +436,11 @@ func dataSourceAlicloudKvstoreInstancesRead(d *schema.ResourceData, meta interfa } var response map[string]interface{} - conn, err := client.NewRedisaClient() - if err != nil { - return WrapError(err) - } - + var err error for { - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(5*time.Minute, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() diff --git a/alicloud/resource_alicloud_kvstore_audit_log_config.go b/alicloud/resource_alicloud_kvstore_audit_log_config.go index a4d8cd61501a..c9c678c91a28 100644 --- a/alicloud/resource_alicloud_kvstore_audit_log_config.go +++ b/alicloud/resource_alicloud_kvstore_audit_log_config.go @@ -5,7 +5,6 @@ import ( "log" "time" - util "github.com/alibabacloud-go/tea-utils/service" "github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -53,12 +52,9 @@ func resourceAlicloudKvstoreAuditLogConfig() *schema.Resource { func resourceAlicloudKvstoreAuditLogConfigCreate(d *schema.ResourceData, meta interface{}) error { client := meta.(*connectivity.AliyunClient) var response map[string]interface{} + var err error action := "ModifyAuditLogConfig" request := make(map[string]interface{}) - conn, err := client.NewRedisaClient() - if err != nil { - return WrapError(err) - } if v, ok := d.GetOkExists("db_audit"); ok { request["DbAudit"] = v } @@ -70,7 +66,7 @@ func resourceAlicloudKvstoreAuditLogConfigCreate(d *schema.ResourceData, meta in } wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -123,11 +119,8 @@ func resourceAlicloudKvstoreAuditLogConfigRead(d *schema.ResourceData, meta inte func resourceAlicloudKvstoreAuditLogConfigUpdate(d *schema.ResourceData, meta interface{}) error { client := meta.(*connectivity.AliyunClient) rKvstoreService := RKvstoreService{client} - conn, err := client.NewRedisaClient() - if err != nil { - return WrapError(err) - } var response map[string]interface{} + var err error update := false request := map[string]interface{}{ "InstanceId": d.Id(), @@ -150,7 +143,7 @@ func resourceAlicloudKvstoreAuditLogConfigUpdate(d *schema.ResourceData, meta in action := "ModifyAuditLogConfig" wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() diff --git a/alicloud/resource_alicloud_kvstore_instance.go b/alicloud/resource_alicloud_kvstore_instance.go index af78bd117baf..70fd9b15ad76 100644 --- a/alicloud/resource_alicloud_kvstore_instance.go +++ b/alicloud/resource_alicloud_kvstore_instance.go @@ -8,8 +8,6 @@ import ( "strings" "time" - util "github.com/alibabacloud-go/tea-utils/service" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" r_kvstore "github.com/aliyun/alibaba-cloud-sdk-go/services/r-kvstore" "github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity" @@ -434,12 +432,9 @@ func resourceAliCloudKvstoreInstanceCreate(d *schema.ResourceData, meta interfac client := meta.(*connectivity.AliyunClient) r_kvstoreService := R_kvstoreService{client} var response map[string]interface{} + var err error action := "CreateInstance" request := make(map[string]interface{}) - conn, err := client.NewRedisClient() - if err != nil { - return WrapError(err) - } request["RegionId"] = client.RegionId request["NetworkType"] = "CLASSIC" @@ -587,11 +582,9 @@ func resourceAliCloudKvstoreInstanceCreate(d *schema.ResourceData, meta interfac } } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutCreate)), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, nil, request, true) if err != nil { if NoCodeRegexRetry(err) { wait() @@ -797,11 +790,8 @@ func resourceAliCloudKvstoreInstanceRead(d *schema.ResourceData, meta interface{ func resourceAliCloudKvstoreInstanceUpdate(d *schema.ResourceData, meta interface{}) error { client := meta.(*connectivity.AliyunClient) r_kvstoreService := R_kvstoreService{client} - conn, err := client.NewRedisaClient() - if err != nil { - return WrapError(err) - } var response map[string]interface{} + var err error d.Partial(true) if d.HasChange("tags") { @@ -904,16 +894,9 @@ func resourceAliCloudKvstoreInstanceUpdate(d *schema.ResourceData, meta interfac if update { action := "TransformInstanceChargeType" - conn, err := client.NewRedisClient() - if err != nil { - return WrapError(err) - } - - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutUpdate)), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), nil, transformInstanceChargeTypeReq, &runtime) + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, nil, transformInstanceChargeTypeReq, false) if err != nil { if NeedRetry(err) { wait() @@ -1231,64 +1214,68 @@ func resourceAliCloudKvstoreInstanceUpdate(d *schema.ResourceData, meta interfac } update = false - modifyInstanceSpecReq := r_kvstore.CreateModifyInstanceSpecRequest() - modifyInstanceSpecReq.InstanceId = d.Id() - modifyInstanceSpecReq.AutoPay = requests.NewBoolean(true) - if v, ok := d.GetOk("effective_time"); ok { - modifyInstanceSpecReq.EffectiveTime = v.(string) + object, err := r_kvstoreService.DescribeKvstoreInstance(d.Id()) + if err != nil { + return WrapError(err) } - if !d.IsNewResource() && d.HasChange("engine_version") { - - modifyInstanceSpecReq.MajorVersion = d.Get("engine_version").(string) + modifyInstanceSpecReq := map[string]interface{}{ + "RegionId": client.RegionId, + "AutoPay": true, + "InstanceId": d.Id(), } - if !d.IsNewResource() && d.HasChange("instance_class") { update = true } if v, ok := d.GetOk("instance_class"); ok { - modifyInstanceSpecReq.InstanceClass = v.(string) + modifyInstanceSpecReq["InstanceClass"] = v } - - if !d.IsNewResource() && d.HasChange("read_only_count") { + // read_only_count and slave_read_only_count may be changed after other attributes changed, like secondary_zone_id + // and ReadOnlyCount and SlaveReadOnlyCount can not be changed together + if !d.IsNewResource() && (d.HasChange("read_only_count") || fmt.Sprint(object["ReadOnlyCount"]) != fmt.Sprint(d.Get("read_only_count"))) { update = true if v, ok := d.GetOkExists("read_only_count"); ok { - modifyInstanceSpecReq.ReadOnlyCount = requests.NewInteger(v.(int)) + modifyInstanceSpecReq["ReadOnlyCount"] = v } } + if v, ok := d.GetOk("effective_time"); ok { + modifyInstanceSpecReq["EffectiveTime"] = v + } + + if v, ok := d.GetOk("business_info"); ok { + modifyInstanceSpecReq["BusinessInfo"] = v + } + + if v, ok := d.GetOk("coupon_no"); ok { + modifyInstanceSpecReq["CouponNo"] = v + } + + if v, ok := d.GetOkExists("force_upgrade"); ok { + modifyInstanceSpecReq["ForceUpgrade"] = v + } + + if v, ok := d.GetOk("order_type"); ok { + modifyInstanceSpecReq["OrderType"] = v + } + if update { - if _, ok := d.GetOk("business_info"); ok { - modifyInstanceSpecReq.BusinessInfo = d.Get("business_info").(string) - } - if _, ok := d.GetOk("coupon_no"); ok { - modifyInstanceSpecReq.CouponNo = d.Get("coupon_no").(string) - } - if _, ok := d.GetOkExists("force_upgrade"); ok { - modifyInstanceSpecReq.ForceUpgrade = requests.NewBoolean(d.Get("force_upgrade").(bool)) - } - if _, ok := d.GetOk("order_type"); ok { - modifyInstanceSpecReq.OrderType = d.Get("order_type").(string) - } - wait := incrementalWait(3*time.Second, 5*time.Second) - err := resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutUpdate)), func() *resource.RetryError { - modifyInstanceSpecReq.ClientToken = buildClientToken(modifyInstanceSpecReq.GetActionName()) - args := *modifyInstanceSpecReq - raw, err := client.WithRKvstoreClient(func(r_kvstoreClient *r_kvstore.Client) (interface{}, error) { - return r_kvstoreClient.ModifyInstanceSpec(&args) - }) + action := "ModifyInstanceSpec" + wait := incrementalWait(3*time.Second, 3*time.Second) + err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutUpdate)), func() *resource.RetryError { + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, nil, modifyInstanceSpecReq, false) if err != nil { - if IsExpectedErrors(err, []string{"MissingRedisUsedmemoryUnsupportPerfItem", "Task.Conflict"}) { + if IsExpectedErrors(err, []string{"MissingRedisUsedmemoryUnsupportPerfItem", "Task.Conflict"}) || NeedRetry(err) { wait() return resource.RetryableError(err) } return resource.NonRetryableError(err) } - addDebug(request.GetActionName(), raw) + addDebug(action, response, modifyInstanceSpecReq) return nil }) if err != nil { - return WrapErrorf(err, DefaultErrorMsg, d.Id(), modifyInstanceSpecReq.GetActionName(), AlibabaCloudSdkGoERROR) + return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR) } instanceStatusConf := BuildStateConf([]string{}, []string{"Normal"}, d.Timeout(schema.TimeoutUpdate), 1*time.Minute, r_kvstoreService.KvstoreInstanceAttributeRefreshFunc(d.Id(), "InstanceStatus")) @@ -1301,16 +1288,47 @@ func resourceAliCloudKvstoreInstanceUpdate(d *schema.ResourceData, meta interfac return WrapErrorf(err, IdMsg, d.Id()) } - if modifyInstanceSpecReq.EffectiveTime != "MaintainTime" && d.HasChange("instance_class") { - stateConf := BuildStateConf([]string{}, []string{modifyInstanceSpecReq.InstanceClass}, d.Timeout(schema.TimeoutUpdate), 1*time.Minute, r_kvstoreService.KvstoreInstanceAttributeRefreshFunc(d.Id(), "RealInstanceClass")) + if fmt.Sprint(modifyInstanceSpecReq["EffectiveTime"]) != "MaintainTime" && d.HasChange("instance_class") { + stateConf := BuildStateConf([]string{}, []string{modifyInstanceSpecReq["InstanceClass"].(string)}, d.Timeout(schema.TimeoutUpdate), 1*time.Minute, r_kvstoreService.KvstoreInstanceAttributeRefreshFunc(d.Id(), "RealInstanceClass")) if _, err := stateConf.WaitForState(); err != nil { return WrapErrorf(err, IdMsg, d.Id()) } } + } - d.SetPartial("engine_version") - d.SetPartial("instance_class") - d.SetPartial("read_only_count") + if !d.IsNewResource() && (d.HasChange("slave_read_only_count") || fmt.Sprint(object["SlaveReadOnlyCount"]) != fmt.Sprint(d.Get("slave_read_only_count"))) { + update = true + if v, ok := d.GetOk("slave_read_only_count"); ok { + modifyInstanceSpecReq["SlaveReadOnlyCount"] = v + } + delete(modifyInstanceSpecReq, "ReadOnlyCount") + action := "ModifyInstanceSpec" + wait := incrementalWait(3*time.Second, 3*time.Second) + err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutUpdate)), func() *resource.RetryError { + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, nil, modifyInstanceSpecReq, false) + if err != nil { + if IsExpectedErrors(err, []string{"MissingRedisUsedmemoryUnsupportPerfItem", "Task.Conflict"}) || NeedRetry(err) { + wait() + return resource.RetryableError(err) + } + return resource.NonRetryableError(err) + } + addDebug(action, response, modifyInstanceSpecReq) + return nil + }) + if err != nil { + return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR) + } + + instanceStatusConf := BuildStateConf([]string{}, []string{"Normal"}, d.Timeout(schema.TimeoutUpdate), 1*time.Minute, r_kvstoreService.KvstoreInstanceAttributeRefreshFunc(d.Id(), "InstanceStatus")) + if _, err := instanceStatusConf.WaitForState(); err != nil { + return WrapErrorf(err, IdMsg, d.Id()) + } + + stateConf := BuildStateConf([]string{}, []string{"true"}, d.Timeout(schema.TimeoutUpdate), 1*time.Minute, r_kvstoreService.KvstoreInstanceAttributeRefreshFunc(d.Id(), "IsOrderCompleted")) + if _, err := stateConf.WaitForState(); err != nil { + return WrapErrorf(err, IdMsg, d.Id()) + } } update = false @@ -1441,7 +1459,7 @@ func resourceAliCloudKvstoreInstanceUpdate(d *schema.ResourceData, meta interfac action := "ModifyInstanceTDE" wait := incrementalWait(3*time.Second, 3*time.Second) err := resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutUpdate)), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), nil, modifyInstanceTDERequest, &util.RuntimeOptions{}) + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, nil, modifyInstanceTDERequest, false) if err != nil { if NeedRetry(err) { wait() @@ -1480,18 +1498,12 @@ func resourceAliCloudKvstoreInstanceUpdate(d *schema.ResourceData, meta interfac if removed > 0 { action := "DeleteShardingNode" - conn, err = client.NewRedisClient() - if err != nil { - return WrapError(err) - } request := make(map[string]interface{}) request["InstanceId"] = d.Id() request["ShardCount"] = removed - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, nil, request, false) if err != nil { if NeedRetry(err) { @@ -1522,19 +1534,13 @@ func resourceAliCloudKvstoreInstanceUpdate(d *schema.ResourceData, meta interfac if added > 0 { action := "AddShardingNode" - conn, err = client.NewRedisClient() - if err != nil { - return WrapError(err) - } request := make(map[string]interface{}) request["InstanceId"] = d.Id() request["ClientToken"] = buildClientToken(action) request["ShardCount"] = added - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, nil, request, true) request["ClientToken"] = buildClientToken(action) if err != nil { if NeedRetry(err) { @@ -1566,85 +1572,6 @@ func resourceAliCloudKvstoreInstanceUpdate(d *schema.ResourceData, meta interfac } - update = false - modifySlaveReadOnlyCountReq := map[string]interface{}{ - "RegionId": client.RegionId, - "AutoPay": true, - "InstanceId": d.Id(), - } - - if v, ok := d.GetOk("instance_class"); ok { - modifySlaveReadOnlyCountReq["InstanceClass"] = v - } - - if !d.IsNewResource() && d.HasChange("slave_read_only_count") { - update = true - - if v, ok := d.GetOk("slave_read_only_count"); ok { - modifySlaveReadOnlyCountReq["SlaveReadOnlyCount"] = v - } - } - - if v, ok := d.GetOk("effective_time"); ok { - modifySlaveReadOnlyCountReq["EffectiveTime"] = v - } - - if v, ok := d.GetOk("business_info"); ok { - modifySlaveReadOnlyCountReq["BusinessInfo"] = v - } - - if v, ok := d.GetOk("coupon_no"); ok { - modifySlaveReadOnlyCountReq["CouponNo"] = v - } - - if v, ok := d.GetOkExists("force_upgrade"); ok { - modifySlaveReadOnlyCountReq["ForceUpgrade"] = v - } - - if v, ok := d.GetOk("order_type"); ok { - modifySlaveReadOnlyCountReq["OrderType"] = v - } - - if update { - action := "ModifyInstanceSpec" - conn, err := client.NewRedisClient() - if err != nil { - return WrapError(err) - } - - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) - wait := incrementalWait(3*time.Second, 3*time.Second) - err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutUpdate)), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), nil, modifySlaveReadOnlyCountReq, &runtime) - if err != nil { - if IsExpectedErrors(err, []string{"MissingRedisUsedmemoryUnsupportPerfItem", "Task.Conflict"}) || NeedRetry(err) { - wait() - return resource.RetryableError(err) - } - return resource.NonRetryableError(err) - } - return nil - }) - addDebug(action, response, modifySlaveReadOnlyCountReq) - - if err != nil { - return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR) - } - - instanceStatusConf := BuildStateConf([]string{}, []string{"Normal"}, d.Timeout(schema.TimeoutUpdate), 1*time.Minute, r_kvstoreService.KvstoreInstanceAttributeRefreshFunc(d.Id(), "InstanceStatus")) - if _, err := instanceStatusConf.WaitForState(); err != nil { - return WrapErrorf(err, IdMsg, d.Id()) - } - - stateConf := BuildStateConf([]string{}, []string{"true"}, d.Timeout(schema.TimeoutUpdate), 1*time.Minute, r_kvstoreService.KvstoreInstanceAttributeRefreshFunc(d.Id(), "IsOrderCompleted")) - if _, err := stateConf.WaitForState(); err != nil { - return WrapErrorf(err, IdMsg, d.Id()) - } - - d.SetPartial("slave_read_only_count") - } - update = false modifyDBInstanceAutoUpgradeReq := map[string]interface{}{ "DBInstanceId": d.Id(), @@ -1659,16 +1586,9 @@ func resourceAliCloudKvstoreInstanceUpdate(d *schema.ResourceData, meta interfac if update { action := "ModifyDBInstanceAutoUpgrade" - conn, err := client.NewRedisClient() - if err != nil { - return WrapError(err) - } - - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutUpdate)), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), nil, modifyDBInstanceAutoUpgradeReq, &runtime) + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, nil, modifyDBInstanceAutoUpgradeReq, false) if err != nil { if NeedRetry(err) { wait() @@ -1702,16 +1622,9 @@ func resourceAliCloudKvstoreInstanceUpdate(d *schema.ResourceData, meta interfac if update { action := "ModifyInstanceBandwidth" - conn, err := client.NewRedisClient() - if err != nil { - return WrapError(err) - } - - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutUpdate)), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), nil, modifyInstanceBandwidthReq, &runtime) + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, nil, modifyInstanceBandwidthReq, false) if err != nil { if NeedRetry(err) { wait() @@ -1763,10 +1676,6 @@ func resourceAliCloudKvstoreInstanceDelete(d *schema.ResourceData, meta interfac } var response map[string]interface{} - conn, err := client.NewRedisClient() - if err != nil { - return WrapError(err) - } action := "DeleteInstance" request := map[string]interface{}{ "InstanceId": d.Id(), @@ -1775,11 +1684,9 @@ func resourceAliCloudKvstoreInstanceDelete(d *schema.ResourceData, meta interfac if v, ok := d.GetOk("global_instance_id"); ok { request["GlobalInstanceId"] = v.(string) } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutDelete)), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, nil, request, true) if err != nil { if NoCodeRegexRetry(err) || NeedRetry(err) { wait() diff --git a/alicloud/resource_alicloud_kvstore_instance_test.go b/alicloud/resource_alicloud_kvstore_instance_test.go index 3b369a003b22..1cfbd5ef6050 100644 --- a/alicloud/resource_alicloud_kvstore_instance_test.go +++ b/alicloud/resource_alicloud_kvstore_instance_test.go @@ -6,8 +6,6 @@ import ( "testing" "github.com/PaesslerAG/jsonpath" - util "github.com/alibabacloud-go/tea-utils/service" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "strings" @@ -31,12 +29,6 @@ func testSweepKVStoreInstances(region string) error { return fmt.Errorf("error getting Alicloud client: %s", err) } client := rawClient.(*connectivity.AliyunClient) - - conn, err := client.NewRedisaClient() - if err != nil { - return WrapError(err) - } - prefixes := []string{ "tf-testAcc", "tf_testAcc", @@ -53,9 +45,7 @@ func testSweepKVStoreInstances(region string) error { for _, instanceType := range []string{string(KVStoreRedis), string(KVStoreMemcache)} { request["InstanceType"] = instanceType for { - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, nil, request, true) if err != nil { log.Printf("[ERROR] Failed to retrieve VPC in service list: %s", err) return nil @@ -98,7 +88,7 @@ func testSweepKVStoreInstances(region string) error { } wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(1*time.Minute, func() *resource.RetryError { - _, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + _, err = client.RpcPost("R-kvstore", "2015-01-01", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -117,7 +107,7 @@ func testSweepKVStoreInstances(region string) error { } wait = incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(1*time.Minute, func() *resource.RetryError { - _, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + _, err = client.RpcPost("R-kvstore", "2015-01-01", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -2328,10 +2318,12 @@ func TestAccAliCloudKVStoreRedisInstance_5_0_memory_classic_cluster(t *testing.T }, { Config: testAccConfig(map[string]interface{}{ + "ssl_enable": "Disable", "private_connection_prefix": fmt.Sprintf("privateprefix%d", rand), }), Check: resource.ComposeTestCheckFunc( testAccCheck(map[string]string{ + "ssl_enable": "Disable", "private_connection_prefix": CHECKSET, }), ), diff --git a/alicloud/resource_alicloud_redis_tair_instance.go b/alicloud/resource_alicloud_redis_tair_instance.go index a7ba2056f810..d3a8aa95aa86 100644 --- a/alicloud/resource_alicloud_redis_tair_instance.go +++ b/alicloud/resource_alicloud_redis_tair_instance.go @@ -276,10 +276,7 @@ func resourceAliCloudRedisTairInstanceCreate(d *schema.ResourceData, meta interf var request map[string]interface{} var response map[string]interface{} query := make(map[string]interface{}) - conn, err := client.NewRedisClient() - if err != nil { - return WrapError(err) - } + var err error request = make(map[string]interface{}) request["RegionId"] = client.RegionId request["ClientToken"] = buildClientToken(action) @@ -361,11 +358,9 @@ func resourceAliCloudRedisTairInstanceCreate(d *schema.ResourceData, meta interf if v, ok := d.GetOk("connection_string_prefix"); ok { request["ConnectionStringPrefix"] = v } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, query, request, true) if err != nil { if NeedRetry(err) { wait() @@ -567,10 +562,7 @@ func resourceAliCloudRedisTairInstanceUpdate(d *schema.ResourceData, meta interf d.Partial(true) action := "ModifyInstanceAttribute" - conn, err := client.NewRedisClient() - if err != nil { - return WrapError(err) - } + var err error request = make(map[string]interface{}) query = make(map[string]interface{}) request["InstanceId"] = d.Id() @@ -590,7 +582,7 @@ func resourceAliCloudRedisTairInstanceUpdate(d *schema.ResourceData, meta interf runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, query, request, true) if err != nil { if NeedRetry(err) { wait() @@ -612,10 +604,6 @@ func resourceAliCloudRedisTairInstanceUpdate(d *schema.ResourceData, meta interf } update = false action = "ModifyInstanceSpec" - conn, err = client.NewRedisClient() - if err != nil { - return WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) request["InstanceId"] = d.Id() @@ -648,7 +636,7 @@ func resourceAliCloudRedisTairInstanceUpdate(d *schema.ResourceData, meta interf runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, query, request, true) if err != nil { if NeedRetry(err) { wait() @@ -670,10 +658,6 @@ func resourceAliCloudRedisTairInstanceUpdate(d *schema.ResourceData, meta interf } update = false action = "ModifyResourceGroup" - conn, err = client.NewRedisClient() - if err != nil { - return WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) request["InstanceId"] = d.Id() @@ -688,7 +672,7 @@ func resourceAliCloudRedisTairInstanceUpdate(d *schema.ResourceData, meta interf runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, query, request, true) if err != nil { if NeedRetry(err) { wait() @@ -705,10 +689,6 @@ func resourceAliCloudRedisTairInstanceUpdate(d *schema.ResourceData, meta interf } update = false action = "ModifyInstanceMajorVersion" - conn, err = client.NewRedisClient() - if err != nil { - return WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) request["InstanceId"] = d.Id() @@ -725,7 +705,7 @@ func resourceAliCloudRedisTairInstanceUpdate(d *schema.ResourceData, meta interf runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, query, request, true) if err != nil { if NeedRetry(err) { wait() @@ -747,10 +727,6 @@ func resourceAliCloudRedisTairInstanceUpdate(d *schema.ResourceData, meta interf } update = false action = "ModifySecurityGroupConfiguration" - conn, err = client.NewRedisClient() - if err != nil { - return WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) request["DBInstanceId"] = d.Id() @@ -764,7 +740,7 @@ func resourceAliCloudRedisTairInstanceUpdate(d *schema.ResourceData, meta interf runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, query, request, true) if err != nil { if NeedRetry(err) { wait() @@ -781,10 +757,6 @@ func resourceAliCloudRedisTairInstanceUpdate(d *schema.ResourceData, meta interf } update = false action = "TransformInstanceChargeType" - conn, err = client.NewRedisClient() - if err != nil { - return WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) request["InstanceId"] = d.Id() @@ -808,7 +780,7 @@ func resourceAliCloudRedisTairInstanceUpdate(d *schema.ResourceData, meta interf runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, query, request, true) if err != nil { if NeedRetry(err) { wait() @@ -825,10 +797,6 @@ func resourceAliCloudRedisTairInstanceUpdate(d *schema.ResourceData, meta interf } update = false action = "ModifyInstanceSSL" - conn, err = client.NewRedisClient() - if err != nil { - return WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) request["InstanceId"] = d.Id() @@ -847,7 +815,7 @@ func resourceAliCloudRedisTairInstanceUpdate(d *schema.ResourceData, meta interf runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, query, request, true) if err != nil { if NeedRetry(err) { wait() @@ -869,10 +837,6 @@ func resourceAliCloudRedisTairInstanceUpdate(d *schema.ResourceData, meta interf } update = false action = "ModifyInstanceBandwidth" - conn, err = client.NewRedisClient() - if err != nil { - return WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) request["InstanceId"] = d.Id() @@ -886,7 +850,7 @@ func resourceAliCloudRedisTairInstanceUpdate(d *schema.ResourceData, meta interf runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, query, request, true) if err != nil { if NeedRetry(err) { wait() @@ -908,10 +872,6 @@ func resourceAliCloudRedisTairInstanceUpdate(d *schema.ResourceData, meta interf } update = false action = "ModifyInstanceVpcAuthMode" - conn, err = client.NewRedisClient() - if err != nil { - return WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) request["InstanceId"] = d.Id() @@ -925,7 +885,7 @@ func resourceAliCloudRedisTairInstanceUpdate(d *schema.ResourceData, meta interf runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, query, request, true) if err != nil { if NeedRetry(err) { wait() @@ -947,10 +907,6 @@ func resourceAliCloudRedisTairInstanceUpdate(d *schema.ResourceData, meta interf } update = false action = "ModifySecurityIps" - conn, err = client.NewRedisClient() - if err != nil { - return WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) request["InstanceId"] = d.Id() @@ -974,7 +930,7 @@ func resourceAliCloudRedisTairInstanceUpdate(d *schema.ResourceData, meta interf runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, query, request, true) if err != nil { if NeedRetry(err) { wait() @@ -996,10 +952,6 @@ func resourceAliCloudRedisTairInstanceUpdate(d *schema.ResourceData, meta interf } update = false action = "ModifyInstanceConfig" - conn, err = client.NewRedisClient() - if err != nil { - return WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) request["InstanceId"] = d.Id() @@ -1039,7 +991,7 @@ func resourceAliCloudRedisTairInstanceUpdate(d *schema.ResourceData, meta interf runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, query, request, true) if err != nil { if NeedRetry(err) { wait() @@ -1069,10 +1021,6 @@ func resourceAliCloudRedisTairInstanceUpdate(d *schema.ResourceData, meta interf if removed > 0 { action := "DeleteShardingNode" - conn, err := client.NewRedisClient() - if err != nil { - return WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) request["InstanceId"] = d.Id() @@ -1083,7 +1031,7 @@ func resourceAliCloudRedisTairInstanceUpdate(d *schema.ResourceData, meta interf runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, query, request, true) if err != nil { if NeedRetry(err) { wait() @@ -1107,10 +1055,6 @@ func resourceAliCloudRedisTairInstanceUpdate(d *schema.ResourceData, meta interf if added > 0 { action := "AddShardingNode" - conn, err := client.NewRedisClient() - if err != nil { - return WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) request["InstanceId"] = d.Id() @@ -1122,7 +1066,7 @@ func resourceAliCloudRedisTairInstanceUpdate(d *schema.ResourceData, meta interf runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, query, request, true) if err != nil { if NeedRetry(err) { wait() @@ -1167,10 +1111,7 @@ func resourceAliCloudRedisTairInstanceDelete(d *schema.ResourceData, meta interf var request map[string]interface{} var response map[string]interface{} query := make(map[string]interface{}) - conn, err := client.NewRedisClient() - if err != nil { - return WrapError(err) - } + var err error request = make(map[string]interface{}) request["InstanceId"] = d.Id() @@ -1178,7 +1119,7 @@ func resourceAliCloudRedisTairInstanceDelete(d *schema.ResourceData, meta interf runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, query, request, true) if err != nil { if NeedRetry(err) { diff --git a/alicloud/service_alicloud_r_kvstore.go b/alicloud/service_alicloud_r_kvstore.go index 334d6409fcb7..1bc6ab57f2d9 100644 --- a/alicloud/service_alicloud_r_kvstore.go +++ b/alicloud/service_alicloud_r_kvstore.go @@ -245,20 +245,14 @@ func (s *R_kvstoreService) DescribeSecurityGroupConfiguration(id string) (object func (s *R_kvstoreService) DescribeKvstoreInstance(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewRedisaClient() - if err != nil { - return nil, WrapError(err) - } action := "DescribeInstanceAttribute" request := map[string]interface{}{ "RegionId": s.client.RegionId, "InstanceId": id, } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(5*time.Minute, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), nil, request, &runtime) + response, err = s.client.RpcPost("R-kvstore", "2015-01-01", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -323,20 +317,14 @@ func (s *R_kvstoreService) KvstoreInstanceAttributeRefreshFunc(id, attribute str func (s *R_kvstoreService) DescribeKvstoreInstances(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewRedisaClient() - if err != nil { - return nil, WrapError(err) - } action := "DescribeInstances" request := map[string]interface{}{ "RegionId": s.client.RegionId, "InstanceIds": id, } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(5*time.Minute, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), nil, request, &runtime) + response, err = s.client.RpcPost("R-kvstore", "2015-01-01", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -387,21 +375,15 @@ func (s *R_kvstoreService) KvstoreInstancesStateRefreshFunc(id string, failState func (s *R_kvstoreService) DescribeKvstoreInstanceDeleted(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewRedisaClient() - if err != nil { - return nil, WrapError(err) - } action := "DescribeInstances" request := map[string]interface{}{ "RegionId": s.client.RegionId, "InstanceIds": id, "Expired": true, } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(5*time.Minute, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), nil, request, &runtime) + response, err = s.client.RpcPost("R-kvstore", "2015-01-01", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -593,20 +575,14 @@ func (s *R_kvstoreService) DescribeBackupPolicy(id string) (object r_kvstore.Des func (s *RKvstoreService) DescribeKvstoreAuditLogConfig(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewRedisaClient() - if err != nil { - return nil, WrapError(err) - } action := "DescribeAuditLogConfig" request := map[string]interface{}{ "RegionId": s.client.RegionId, "InstanceId": id, } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(5*time.Minute, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), nil, request, &runtime) + response, err = s.client.RpcPost("R-kvstore", "2015-01-01", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -633,10 +609,6 @@ func (s *RKvstoreService) DescribeKvstoreAuditLogConfig(id string) (object map[s func (s *RKvstoreService) DescribeInstanceAttribute(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewRedisaClient() - if err != nil { - return nil, WrapError(err) - } action := "DescribeInstanceAttribute" request := map[string]interface{}{ "InstanceId": id, @@ -645,7 +617,7 @@ func (s *RKvstoreService) DescribeInstanceAttribute(id string) (object map[strin runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(5*time.Minute, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), nil, request, &runtime) + response, err = s.client.RpcPost("R-kvstore", "2015-01-01", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -699,20 +671,14 @@ func (s *RKvstoreService) KvstoreAuditLogConfigStateRefreshFunc(id string, failS func (s *RKvstoreService) DescribeInstanceAutoRenewalAttribute(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewRedisaClient() - if err != nil { - return nil, WrapError(err) - } action := "DescribeInstanceAutoRenewalAttribute" request := map[string]interface{}{ "DBInstanceId": id, "RegionId": s.client.RegionId, } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(5*time.Minute, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), nil, request, &runtime) + response, err = s.client.RpcPost("R-kvstore", "2015-01-01", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -746,20 +712,14 @@ func (s *RKvstoreService) DescribeInstanceAutoRenewalAttribute(id string) (objec func (s *RKvstoreService) DescribeInstanceSSL(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewRedisaClient() - if err != nil { - return nil, WrapError(err) - } action := "DescribeInstanceSSL" request := map[string]interface{}{ "InstanceId": id, "RegionId": s.client.RegionId, } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(5*time.Minute, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), nil, request, &runtime) + response, err = s.client.RpcPost("R-kvstore", "2015-01-01", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -781,20 +741,14 @@ func (s *RKvstoreService) DescribeInstanceSSL(id string) (object map[string]inte func (s *RKvstoreService) DescribeSecurityGroupConfiguration(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewRedisaClient() - if err != nil { - return nil, WrapError(err) - } action := "DescribeSecurityGroupConfiguration" request := map[string]interface{}{ "InstanceId": id, "RegionId": s.client.RegionId, } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(5*time.Minute, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), nil, request, &runtime) + response, err = s.client.RpcPost("R-kvstore", "2015-01-01", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -822,20 +776,14 @@ func (s *RKvstoreService) DescribeSecurityGroupConfiguration(id string) (object func (s *RKvstoreService) DescribeSecurityIps(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewRedisaClient() - if err != nil { - return nil, WrapError(err) - } action := "DescribeSecurityIps" request := map[string]interface{}{ "InstanceId": id, "RegionId": s.client.RegionId, } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(5*time.Minute, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), nil, request, &runtime) + response, err = s.client.RpcPost("R-kvstore", "2015-01-01", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -868,19 +816,13 @@ func (s *RKvstoreService) DescribeSecurityIps(id string) (object map[string]inte func (s *RKvstoreService) DescribeInstanceTDEStatus(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewRedisaClient() - if err != nil { - return nil, WrapError(err) - } action := "DescribeInstanceTDEStatus" request := map[string]interface{}{ "InstanceId": id, } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(5*time.Minute, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), nil, request, &runtime) + response, err = s.client.RpcPost("R-kvstore", "2015-01-01", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -904,19 +846,13 @@ func (s *RKvstoreService) DescribeInstanceTDEStatus(id string) (object map[strin func (s *RKvstoreService) DescribeEncryptionKey(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewRedisaClient() - if err != nil { - return nil, WrapError(err) - } action := "DescribeEncryptionKey" request := map[string]interface{}{ "InstanceId": id, } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(5*time.Minute, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), nil, request, &runtime) + response, err = s.client.RpcPost("R-kvstore", "2015-01-01", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -941,21 +877,13 @@ func (s *RKvstoreService) DescribeEncryptionKey(id string) (object map[string]in func (s *R_kvstoreService) DescribeKvStoreInstanceNetInfo(id string) (objects []interface{}, err error) { var response map[string]interface{} action := "DescribeDBInstanceNetInfo" - - conn, err := s.client.NewRedisaClient() - if err != nil { - return nil, WrapError(err) - } - request := map[string]interface{}{ "InstanceId": id, } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(5*time.Minute, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), nil, request, &runtime) + response, err = s.client.RpcPost("R-kvstore", "2015-01-01", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -988,21 +916,12 @@ func (s *R_kvstoreService) DescribeKvStoreInstanceNetInfo(id string) (objects [] func (s *R_kvstoreService) DescribeKvStoreEngineVersion(id string) (object map[string]interface{}, err error) { var response map[string]interface{} action := "DescribeEngineVersion" - - conn, err := s.client.NewRedisaClient() - if err != nil { - return nil, WrapError(err) - } - request := map[string]interface{}{ "InstanceId": id, } - - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(5*time.Minute, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), nil, request, &runtime) + response, err = s.client.RpcPost("R-kvstore", "2015-01-01", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() diff --git a/alicloud/service_alicloud_redis_v2.go b/alicloud/service_alicloud_redis_v2.go index f37aa6d66067..bc3c7100ccb2 100644 --- a/alicloud/service_alicloud_redis_v2.go +++ b/alicloud/service_alicloud_redis_v2.go @@ -6,8 +6,6 @@ import ( "time" "github.com/PaesslerAG/jsonpath" - rpc "github.com/alibabacloud-go/tea-rpc/client" - util "github.com/alibabacloud-go/tea-utils/service" "github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -25,20 +23,14 @@ func (s *RedisServiceV2) DescribeRedisTairInstance(id string) (object map[string var response map[string]interface{} var query map[string]interface{} action := "DescribeInstanceAttribute" - conn, err := client.NewRedisClient() - if err != nil { - return object, WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) request["InstanceId"] = id request["RegionId"] = client.RegionId - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(1*time.Minute, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, query, request, true) if err != nil { if NeedRetry(err) { @@ -74,20 +66,14 @@ func (s *RedisServiceV2) DescribeTairInstanceDescribeInstanceConfig(id string) ( var response map[string]interface{} var query map[string]interface{} action := "DescribeInstanceConfig" - conn, err := client.NewRedisClient() - if err != nil { - return object, WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) request["InstanceId"] = id request["RegionId"] = client.RegionId - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(1*time.Minute, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, query, request, true) if err != nil { if NeedRetry(err) { @@ -114,20 +100,14 @@ func (s *RedisServiceV2) DescribeDescribeSecurityIps(id, securityIpGroupName str var response map[string]interface{} var query map[string]interface{} action := "DescribeSecurityIps" - conn, err := client.NewRedisClient() - if err != nil { - return object, WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) request["InstanceId"] = id request["RegionId"] = client.RegionId - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(1*time.Minute, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, query, request, true) if err != nil { if NeedRetry(err) { @@ -174,20 +154,14 @@ func (s *RedisServiceV2) DescribeTairInstanceDescribeSecurityGroupConfiguration( var response map[string]interface{} var query map[string]interface{} action := "DescribeSecurityGroupConfiguration" - conn, err := client.NewRedisClient() - if err != nil { - return object, WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) request["InstanceId"] = id request["RegionId"] = client.RegionId - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(1*time.Minute, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, query, request, true) if err != nil { if NeedRetry(err) { @@ -223,20 +197,14 @@ func (s *RedisServiceV2) DescribeTairInstanceDescribeInstanceSSL(id string) (obj var response map[string]interface{} var query map[string]interface{} action := "DescribeInstanceSSL" - conn, err := client.NewRedisClient() - if err != nil { - return object, WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) request["InstanceId"] = id request["RegionId"] = client.RegionId - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(1*time.Minute, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, query, request, true) if err != nil { if NeedRetry(err) { @@ -263,20 +231,14 @@ func (s *RedisServiceV2) DescribeTairInstanceDescribeIntranetAttribute(id string var response map[string]interface{} var query map[string]interface{} action := "DescribeIntranetAttribute" - conn, err := client.NewRedisClient() - if err != nil { - return object, WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) request["InstanceId"] = id request["RegionId"] = client.RegionId - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(1*time.Minute, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, query, request, true) if err != nil { if NeedRetry(err) { @@ -334,7 +296,6 @@ func (s *RedisServiceV2) SetResourceTags(d *schema.ResourceData, resourceType st if d.HasChange("tags") { var err error var action string - var conn *rpc.Client client := s.client var request map[string]interface{} var response map[string]interface{} @@ -349,10 +310,6 @@ func (s *RedisServiceV2) SetResourceTags(d *schema.ResourceData, resourceType st } if len(removedTagKeys) > 0 { action = "UntagResources" - conn, err = client.NewRedisClient() - if err != nil { - return WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) request["ResourceId.1"] = d.Id() @@ -362,11 +319,9 @@ func (s *RedisServiceV2) SetResourceTags(d *schema.ResourceData, resourceType st request[fmt.Sprintf("TagKey.%d", i+1)] = key } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, query, request, false) if err != nil { if NeedRetry(err) { wait() @@ -385,10 +340,6 @@ func (s *RedisServiceV2) SetResourceTags(d *schema.ResourceData, resourceType st if len(added) > 0 { action = "TagResources" - conn, err = client.NewRedisClient() - if err != nil { - return WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) request["ResourceId.1"] = d.Id() @@ -401,11 +352,9 @@ func (s *RedisServiceV2) SetResourceTags(d *schema.ResourceData, resourceType st } request["ResourceType"] = resourceType - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("R-kvstore", "2015-01-01", action, query, request, false) if err != nil { if NeedRetry(err) { wait()