Skip to content

Commit f971870

Browse files
authored
fix(postgresql): [121712351] tencentcloud_postgresql_instance update query interface limit count (#3084)
* add * add * add * add * add
1 parent 0ea0975 commit f971870

File tree

4 files changed

+67
-19
lines changed

4 files changed

+67
-19
lines changed

.changelog/3084.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_postgresql_instance: update query interface limit count
3+
```

tencentcloud/services/postgresql/resource_tc_postgresql_instance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ func ResourceTencentCloudPostgresqlInstance() *schema.Resource {
166166
},
167167
"root_user": {
168168
Type: schema.TypeString,
169-
ForceNew: true,
170169
Optional: true,
171170
Default: "root",
172171
Description: "Instance root account name. This parameter is optional, Default value is `root`.",
@@ -1004,6 +1003,7 @@ func resourceTencentCloudPostgresqlInstanceUpdate(d *schema.ResourceData, meta i
10041003
// "auto_renew_flag",
10051004
// "auto_voucher",
10061005
"voucher_ids",
1006+
"root_user",
10071007
); err != nil {
10081008
return err
10091009
}

tencentcloud/services/postgresql/service_tencentcloud_postgresql.go

Lines changed: 62 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import (
55
"errors"
66
"fmt"
77
"log"
8+
"sort"
89
"strconv"
10+
"strings"
911
"time"
1012

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

825827
func (me *PostgresqlService) DescribeRootUser(ctx context.Context, instanceId string) (accounts []*postgresql.AccountInfo, errRet error) {
826828
logId := tccommon.GetLogId(ctx)
827-
orderBy := "createTime"
828-
orderByType := "asc"
829-
830829
request := postgresql.NewDescribeAccountsRequest()
831830
request.DBInstanceId = &instanceId
832-
request.OrderBy = &orderBy
833-
request.OrderByType = &orderByType
831+
request.OrderByType = helper.String("asc")
832+
request.OrderBy = helper.String("createTime")
833+
834834
var response *postgresql.DescribeAccountsResponse
835-
errRet = resource.Retry(2*tccommon.ReadRetryTimeout, func() *resource.RetryError {
836-
response, errRet = me.client.UsePostgresqlClient().DescribeAccounts(request)
835+
var tmpList []*postgresql.AccountInfo
836+
837+
var offset, limit int64 = 0, 100
838+
839+
for {
840+
request.Offset = &offset
841+
request.Limit = &limit
842+
ratelimit.Check(request.GetAction())
843+
errRet = resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
844+
result, e := me.client.UsePostgresqlClient().DescribeAccounts(request)
845+
if e != nil {
846+
log.Printf("[CRITAL]%s describe account failed, reason: %v", logId, e)
847+
return tccommon.RetryError(e)
848+
}
849+
850+
if result == nil || result.Response == nil || result.Response.Details == nil {
851+
errRet = fmt.Errorf("TencentCloud SDK return nil response, %+v, %s", result, request.GetAction())
852+
}
853+
854+
response = result
855+
return nil
856+
})
857+
837858
if errRet != nil {
838-
log.Printf("[CRITAL]%s describe account failed, reason: %v", logId, errRet)
839-
return tccommon.RetryError(errRet)
859+
return nil, errRet
840860
}
841-
return nil
842-
})
843-
if errRet != nil {
844-
return nil, errRet
861+
862+
tmpList = append(tmpList, response.Response.Details...)
863+
if len(response.Response.Details) < int(limit) {
864+
break
865+
}
866+
867+
offset += limit
845868
}
846-
if response == nil || response.Response == nil || response.Response.Details == nil {
847-
errRet = fmt.Errorf("TencentCloud SDK return nil response, %+v, %s", response, request.GetAction())
848-
} else {
849-
accounts = response.Response.Details
869+
870+
for _, item := range tmpList {
871+
if item.CreateTime != nil && strings.Contains(*item.CreateTime, "0000-00-00") {
872+
continue
873+
}
874+
875+
accounts = append(accounts, item)
850876
}
851877

878+
sort.Slice(accounts, func(i, j int) bool {
879+
timeStrI := accounts[i].CreateTime
880+
timeStrJ := accounts[j].CreateTime
881+
882+
timeI, errI := time.Parse(tccommon.TENCENTCLOUD_COMMON_TIME_LAYOUT, *timeStrI)
883+
if errI != nil {
884+
fmt.Printf("Error parsing time string %s: %v\n", *timeStrI, errI)
885+
return false
886+
}
887+
888+
timeJ, errJ := time.Parse(tccommon.TENCENTCLOUD_COMMON_TIME_LAYOUT, *timeStrJ)
889+
if errJ != nil {
890+
fmt.Printf("Error parsing time string %s: %v\n", *timeStrJ, errJ)
891+
return false
892+
}
893+
894+
return timeI.Before(timeJ)
895+
})
896+
852897
return accounts, errRet
853898
}
854899

website/docs/r/postgresql_instance.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ The following arguments are supported:
326326
* `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`.
327327
* `project_id` - (Optional, Int) Project id, default value is `0`.
328328
* `public_access_switch` - (Optional, Bool) Indicates whether to enable the access to an instance from public network or not.
329-
* `root_user` - (Optional, String, ForceNew) Instance root account name. This parameter is optional, Default value is `root`.
329+
* `root_user` - (Optional, String) Instance root account name. This parameter is optional, Default value is `root`.
330330
* `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.
331331
* `tags` - (Optional, Map) The available tags within this postgresql.
332332
* `voucher_ids` - (Optional, List: [`String`]) Specify Voucher Ids if `auto_voucher` was `1`, only support using 1 vouchers for now.

0 commit comments

Comments
 (0)