diff --git a/.changelog/3038.txt b/.changelog/3038.txt new file mode 100644 index 0000000000..b81ab7c239 --- /dev/null +++ b/.changelog/3038.txt @@ -0,0 +1,7 @@ +```release-note:enhancement +resource/tencentcloud_clb_listener_default_domain: support retry +``` + +```release-note:enhancement +resource/tencentcloud_clb_listener_rule: support retry +``` diff --git a/tencentcloud/services/clb/resource_tc_clb_listener_default_domain.go b/tencentcloud/services/clb/resource_tc_clb_listener_default_domain.go index 5a6389b880..589dccfa56 100644 --- a/tencentcloud/services/clb/resource_tc_clb_listener_default_domain.go +++ b/tencentcloud/services/clb/resource_tc_clb_listener_default_domain.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" clb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb/v20180317" + sdkErrors "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors" "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" ) @@ -86,15 +87,20 @@ func resourceTencentCloudClbListenerDefaultDomainCreate(d *schema.ResourceData, err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { result, e := client.ModifyDomainAttributes(request) if e != nil { + if sdkError, ok := e.(*sdkErrors.TencentCloudSDKError); ok { + if sdkError.Code == "FailedOperation.ResourceInOperating" { + return resource.RetryableError(e) + } + } + return tccommon.RetryError(e) } else { log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) } - if result == nil { - e = fmt.Errorf("modify domain failed") - return resource.NonRetryableError(e) + if result == nil || result.Response == nil || response.Response.RequestId == nil { + return resource.NonRetryableError(fmt.Errorf("Modify domain attributes failed, Response is nil.")) } response = result @@ -211,15 +217,20 @@ func resourceTencentCloudClbListenerDefaultDomainUpdate(d *schema.ResourceData, err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { result, e := client.ModifyDomainAttributes(request) if e != nil { + if sdkError, ok := e.(*sdkErrors.TencentCloudSDKError); ok { + if sdkError.Code == "FailedOperation.ResourceInOperating" { + return resource.RetryableError(e) + } + } + return tccommon.RetryError(e) } else { log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) } - if result == nil { - e = fmt.Errorf("modify domain failed") - return resource.NonRetryableError(e) + if result == nil || result.Response == nil || response.Response.RequestId == nil { + return resource.NonRetryableError(fmt.Errorf("Modify domain attributes failed, Response is nil.")) } response = result diff --git a/tencentcloud/services/clb/resource_tc_clb_listener_rule.go b/tencentcloud/services/clb/resource_tc_clb_listener_rule.go index 919159da63..3bf22eefba 100644 --- a/tencentcloud/services/clb/resource_tc_clb_listener_rule.go +++ b/tencentcloud/services/clb/resource_tc_clb_listener_rule.go @@ -12,6 +12,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/pkg/errors" clb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb/v20180317" + sdkErrors "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors" "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" ) @@ -344,6 +345,10 @@ func resourceTencentCloudClbListenerRuleCreate(d *schema.ResourceData, meta inte } else { log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + if response == nil || response.Response == nil || response.Response.RequestId == nil { + return resource.NonRetryableError(fmt.Errorf("Create CLB listener rule failed, Response is nil.")) + } + requestId = *response.Response.RequestId retryErr := waitForTaskFinish(requestId, meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClbClient()) if retryErr != nil { @@ -390,10 +395,20 @@ func resourceTencentCloudClbListenerRuleCreate(d *schema.ResourceData, meta inte err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { response, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClbClient().ModifyDomainAttributes(domainRequest) if e != nil { + if sdkError, ok := e.(*sdkErrors.TencentCloudSDKError); ok { + if sdkError.Code == "FailedOperation.ResourceInOperating" { + return resource.RetryableError(e) + } + } + return tccommon.RetryError(e) } else { log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + if response == nil || response.Response == nil || response.Response.RequestId == nil { + return resource.NonRetryableError(fmt.Errorf("Modify domain attributes failed, Response is nil.")) + } + requestId := *response.Response.RequestId retryErr := waitForTaskFinish(requestId, meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClbClient()) if retryErr != nil { @@ -428,6 +443,10 @@ func resourceTencentCloudClbListenerRuleCreate(d *schema.ResourceData, meta inte } else { log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + if response == nil || response.Response == nil || response.Response.RequestId == nil { + return resource.NonRetryableError(fmt.Errorf("Modify rule failed, Response is nil.")) + } + requestId := *response.Response.RequestId retryErr := waitForTaskFinish(requestId, meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClbClient()) if retryErr != nil { @@ -674,6 +693,10 @@ func resourceTencentCloudClbListenerRuleUpdate(d *schema.ResourceData, meta inte } else { log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + if response == nil || response.Response == nil || response.Response.RequestId == nil { + return resource.NonRetryableError(fmt.Errorf("Modify rule failed, Response is nil.")) + } + requestId := *response.Response.RequestId retryErr := waitForTaskFinish(requestId, meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClbClient()) if retryErr != nil { @@ -744,6 +767,10 @@ func resourceTencentCloudClbListenerRuleUpdate(d *schema.ResourceData, meta inte } else { log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + if response == nil || response.Response == nil || response.Response.RequestId == nil { + return resource.NonRetryableError(fmt.Errorf("Modify domain attributes failed, Response is nil.")) + } + requestId := *response.Response.RequestId retryErr := waitForTaskFinish(requestId, meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClbClient()) if retryErr != nil {