Skip to content

fix(postgresql): [121712351] tencentcloud_postgresql_instance update query interface limit count #3084

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
Jan 22, 2025
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/3084.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_postgresql_instance: update query interface limit count
```
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ func ResourceTencentCloudPostgresqlInstance() *schema.Resource {
},
"root_user": {
Type: schema.TypeString,
ForceNew: true,
Optional: true,
Default: "root",
Description: "Instance root account name. This parameter is optional, Default value is `root`.",
Expand Down Expand Up @@ -1004,6 +1003,7 @@ func resourceTencentCloudPostgresqlInstanceUpdate(d *schema.ResourceData, meta i
// "auto_renew_flag",
// "auto_voucher",
"voucher_ids",
"root_user",
); err != nil {
return err
}
Expand Down
79 changes: 62 additions & 17 deletions tencentcloud/services/postgresql/service_tencentcloud_postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"errors"
"fmt"
"log"
"sort"
"strconv"
"strings"
"time"

tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
Expand Down Expand Up @@ -824,31 +826,74 @@ func (me *PostgresqlService) CheckDBInstanceStatus(ctx context.Context, instance

func (me *PostgresqlService) DescribeRootUser(ctx context.Context, instanceId string) (accounts []*postgresql.AccountInfo, errRet error) {
logId := tccommon.GetLogId(ctx)
orderBy := "createTime"
orderByType := "asc"

request := postgresql.NewDescribeAccountsRequest()
request.DBInstanceId = &instanceId
request.OrderBy = &orderBy
request.OrderByType = &orderByType
request.OrderByType = helper.String("asc")
request.OrderBy = helper.String("createTime")

var response *postgresql.DescribeAccountsResponse
errRet = resource.Retry(2*tccommon.ReadRetryTimeout, func() *resource.RetryError {
response, errRet = me.client.UsePostgresqlClient().DescribeAccounts(request)
var tmpList []*postgresql.AccountInfo

var offset, limit int64 = 0, 100

for {
request.Offset = &offset
request.Limit = &limit
ratelimit.Check(request.GetAction())
errRet = resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
result, e := me.client.UsePostgresqlClient().DescribeAccounts(request)
if e != nil {
log.Printf("[CRITAL]%s describe account failed, reason: %v", logId, e)
return tccommon.RetryError(e)
}

if result == nil || result.Response == nil || result.Response.Details == nil {
errRet = fmt.Errorf("TencentCloud SDK return nil response, %+v, %s", result, request.GetAction())
}

response = result
return nil
})

if errRet != nil {
log.Printf("[CRITAL]%s describe account failed, reason: %v", logId, errRet)
return tccommon.RetryError(errRet)
return nil, errRet
}
return nil
})
if errRet != nil {
return nil, errRet

tmpList = append(tmpList, response.Response.Details...)
if len(response.Response.Details) < int(limit) {
break
}

offset += limit
}
if response == nil || response.Response == nil || response.Response.Details == nil {
errRet = fmt.Errorf("TencentCloud SDK return nil response, %+v, %s", response, request.GetAction())
} else {
accounts = response.Response.Details

for _, item := range tmpList {
if item.CreateTime != nil && strings.Contains(*item.CreateTime, "0000-00-00") {
continue
}

accounts = append(accounts, item)
}

sort.Slice(accounts, func(i, j int) bool {
timeStrI := accounts[i].CreateTime
timeStrJ := accounts[j].CreateTime

timeI, errI := time.Parse(tccommon.TENCENTCLOUD_COMMON_TIME_LAYOUT, *timeStrI)
if errI != nil {
fmt.Printf("Error parsing time string %s: %v\n", *timeStrI, errI)
return false
}

timeJ, errJ := time.Parse(tccommon.TENCENTCLOUD_COMMON_TIME_LAYOUT, *timeStrJ)
if errJ != nil {
fmt.Printf("Error parsing time string %s: %v\n", *timeStrJ, errJ)
return false
}

return timeI.Before(timeJ)
})

return accounts, errRet
}

Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/postgresql_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ The following arguments are supported:
* `period` - (Optional, Int) Specify Prepaid period in month. Default `1`. Values: `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `10`, `11`, `12`, `24`, `36`. This field is valid only when creating a `PREPAID` type instance, or updating the charge type from `POSTPAID_BY_HOUR` to `PREPAID`.
* `project_id` - (Optional, Int) Project id, default value is `0`.
* `public_access_switch` - (Optional, Bool) Indicates whether to enable the access to an instance from public network or not.
* `root_user` - (Optional, String, ForceNew) Instance root account name. This parameter is optional, Default value is `root`.
* `root_user` - (Optional, String) Instance root account name. This parameter is optional, Default value is `root`.
* `security_groups` - (Optional, Set: [`String`]) ID of security group. If both vpc_id and subnet_id are not set, this argument should not be set either.
* `tags` - (Optional, Map) The available tags within this postgresql.
* `voucher_ids` - (Optional, List: [`String`]) Specify Voucher Ids if `auto_voucher` was `1`, only support using 1 vouchers for now.
Expand Down
Loading