Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(clb): [121342773] tencentcloud_clb_listener_default_domain support retry #3038

Merged
merged 6 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading