Skip to content

fix: pagination on describe accounts in postgresql#4211

Open
cattyman919 wants to merge 2 commits into
tencentcloudstack:masterfrom
cattyman919:fix/postgresql-accounts-pagination
Open

fix: pagination on describe accounts in postgresql#4211
cattyman919 wants to merge 2 commits into
tencentcloudstack:masterfrom
cattyman919:fix/postgresql-accounts-pagination

Conversation

@cattyman919

@cattyman919 cattyman919 commented Jun 11, 2026

Copy link
Copy Markdown

What

Add pagination to describe accounts postgresql service.

Why

The problem relates to tencentcloud_postgresql_account where it only read the first 20 user in a database instance when checking with the current tfstate.

the function TencentCloudPostgresqlAccountRead is not able to capture all of the users above 20 users in a single database instance. Hence it will return an empty user if the user index is above 20 even though the user exists in the database instance.

func resourceTencentCloudPostgresqlAccountRead(d *schema.ResourceData, meta interface{}) error {
// -------
// DescribePostgresqlAccountById does not read all of the users in the instance due to pagination not being implemented
	account, err := service.DescribePostgresqlAccountById(ctx, dBInstanceId, userName)
	if err != nil {
		return err
	}
// -------
}

Related Problems

I've realized similar function in different database type also doesn't handle pagination as well.

DescribeMongodbInstanceAccountById:

func (me *MongodbService) DescribeMongodbInstanceAccountById(ctx context.Context, instanceId string, userName string) (instanceAccount *mongodb.UserInfo, errRet error) {
logId := tccommon.GetLogId(ctx)
request := mongodb.NewDescribeAccountUsersRequest()
request.InstanceId = &instanceId
defer func() {
if errRet != nil {
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), errRet.Error())
}
}()
ratelimit.Check(request.GetAction())
response, err := me.client.UseMongodbClient().DescribeAccountUsers(request)
if err != nil {
errRet = err
return
}
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
if len(response.Response.Users) < 1 {
return
}
for _, user := range response.Response.Users {
if *user.UserName == userName {
instanceAccount = user
return
}
}
return
}

DescribeCynosdbAccountById:

func (me *CynosdbService) DescribeCynosdbAccountById(ctx context.Context, clusterId string, accountName string, host string) (account *cynosdb.Account, errRet error) {
logId := tccommon.GetLogId(ctx)
request := cynosdb.NewDescribeAccountsRequest()
request.ClusterId = &clusterId
request.AccountNames = []*string{&accountName}
request.Hosts = []*string{&host}
defer func() {
if errRet != nil {
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), errRet.Error())
}
}()
ratelimit.Check(request.GetAction())
response, err := me.client.UseCynosdbClient().DescribeAccounts(request)
if err != nil {
errRet = err
return
}
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
if len(response.Response.AccountSet) < 1 {
return
}
account = response.Response.AccountSet[0]
return
}

DescribeCynosdbAccountsByFilter:

func (me *CynosdbService) DescribeCynosdbAccountsByFilter(ctx context.Context, clusterId string, paramMap map[string]interface{}) (result *cynosdb.DescribeAccountsResponseParams, errRet error) {
logId := tccommon.GetLogId(ctx)
request := cynosdb.NewDescribeAccountsRequest()
defer func() {
if errRet != nil {
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), errRet.Error())
}
}()
request.ClusterId = helper.String(clusterId)
if v, ok := paramMap["account_names"]; ok {
request.AccountNames = helper.InterfacesStringsPoint(v.([]interface{}))
}
if v, ok := paramMap["hosts"]; ok {
request.Hosts = helper.InterfacesStringsPoint(v.([]interface{}))
}
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
response, e := me.client.UseCynosdbClient().DescribeAccounts(request)
if e != nil {
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())
}
result = response.Response
return nil
})
if err != nil {
errRet = err
return
}
return
}

Let me know if you also want me to make changes as well to those other databases to implement pagination.

Type of change

  • New SDKv2 resource / data source
  • New framework resource / data source
  • Modification to an existing resource / data source
  • Bug fix
  • Refactor / internal-only change
  • Documentation only

Checklist

  • make build succeeds locally
  • make fmt produces no diff
  • make lint passes (or pre-existing failures are unrelated)
  • make check-mux passes (SDKv2 + framework mux compatibility)
  • Confirmed the resource/data source type name is not already
    registered in the other stack
    (CI's make check-mux enforces
    this; please double-check before opening the PR)
  • Acceptance tests added or updated (or skipped with justification)
  • Website docs updated under website/docs/r/ or website/docs/d/
  • go.mod changes are accompanied by go mod vendor in the same commit
  • Changelog entry added under .changelog/<PR>.txt (if user-facing)

Notes for reviewers

@cattyman919

Copy link
Copy Markdown
Author

Note: Its seem the pagination issue only happens when fetching postgres accounts. Other database fetching methods seems to work fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant