Skip to content

fix(cdb): [116078583]If the id is empty, try again with the same clienttoken #2684

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

Merged
merged 5 commits into from
Jun 14, 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
3 changes: 3 additions & 0 deletions .changelog/2684.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/tencentcloud_mysql_instance: If the id is empty, retry with the same clienttoken for 10 minutes
```
14 changes: 5 additions & 9 deletions tencentcloud/services/cdb/resource_tc_mysql_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,10 +568,8 @@ func mysqlCreateInstancePayByMonth(ctx context.Context, d *schema.ResourceData,
}

var response *cdb.CreateDBInstanceResponse
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
err := resource.Retry(2*tccommon.WriteRetryTimeout, func() *resource.RetryError {
// shadowed response will not pass to outside
clientToken := helper.BuildToken()
request.ClientToken = &clientToken
r, inErr := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseMysqlClient().CreateDBInstance(request)
if inErr != nil {
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
Expand All @@ -581,7 +579,7 @@ func mysqlCreateInstancePayByMonth(ctx context.Context, d *schema.ResourceData,
return tccommon.RetryError(inErr)
}

if r.Response.InstanceIds == nil && clientToken != "" {
if len(r.Response.InstanceIds) < 1 && clientToken != "" {
return resource.RetryableError(fmt.Errorf("%s returns nil instanceIds but client token provided, retrying", request.GetAction()))
}

Expand Down Expand Up @@ -621,15 +619,13 @@ func mysqlCreateInstancePayByUse(ctx context.Context, d *schema.ResourceData, me
}

var response *cdb.CreateDBInstanceHourResponse
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
err := resource.Retry(2*tccommon.WriteRetryTimeout, func() *resource.RetryError {
// shadowed response will not pass to outside
clientToken := helper.BuildToken()
request.ClientToken = &clientToken
r, inErr := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseMysqlClient().CreateDBInstanceHour(request)
if inErr != nil {
return tccommon.RetryError(inErr)
}
if r.Response.InstanceIds == nil && clientToken != "" {
if len(r.Response.InstanceIds) < 1 && clientToken != "" {
return resource.RetryableError(fmt.Errorf("%s returns nil instanceIds but client token provided, retrying", request.GetAction()))
}
response = r
Expand Down Expand Up @@ -1608,7 +1604,7 @@ func resourceTencentCloudMysqlInstanceDelete(d *schema.ResourceData, meta interf
return resource.NonRetryableError(err)
}
}
if mysqlInfo == nil {
if mysqlInfo == nil || *mysqlInfo.Status == 6 {
return nil
} else {
if mysqlInfo.RoGroups != nil && len(mysqlInfo.RoGroups) > 0 {
Expand Down
Loading