Skip to content

Commit

Permalink
fix(clb): [121342773] tencentcloud_clb_listener_default_domain supp…
Browse files Browse the repository at this point in the history
…ort retry (#3038)

* add

* add

* add

* add

* add

* add
  • Loading branch information
SevenEarth authored Dec 24, 2024
1 parent 7a86856 commit 4e15065
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
7 changes: 7 additions & 0 deletions .changelog/3038.txt
Original file line number Diff line number Diff line change
@@ -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
```
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions tencentcloud/services/clb/resource_tc_clb_listener_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 4e15065

Please sign in to comment.