Skip to content

Bug: DescribeTagResourceById fails to find tags when more than 50 tag entries exist #4293

Description

@kfeldmannwb

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Bug: DescribeTagResourceById fails to find tags when more than 50 tag entries exist

Summary

DescribeTagResourceById in service_tencentcloud_tag.go uses the GetTags API without pagination, causing it to silently fail to locate a tag key/value pair when the account has more tags than the API returns in a single response. The fix adds pagination support and sets MaxResults to the maximum allowed value (1000).

Terraform Version

Terraform v1.15.0 on linux_amd64

Provider version: v1.83.9

Root Cause

The original implementation called GetTags once and iterated over the results. Because no MaxResults was set and PaginationToken was never used, the function only ever checked the first page of results. If the target tag existed beyond the first page, tagRes would remain nil — making Terraform believe the resource does not exist and potentially triggering unwanted plan diffs or destroy operations.

Additionally, the previous code returned a non-retryable error when Tags was an empty slice (e.g. on subsequent pages that exhaust results), which could cause false negatives.

Impact

  • Accounts with large numbers of tags (> the default page size) may experience Terraform incorrectly reporting that a tencentcloud_tag resource does not exist.
  • This can lead to perpetual drift, unnecessary re-creation of tag resources, or failed terraform plan/apply runs.

Fix

The fix in service_tencentcloud_tag.go:

  1. Sets request.MaxResults = 1000 to request the maximum number of results per page.
  2. Wraps the GetTags call in a for loop that follows PaginationToken until all pages are exhausted.
  3. Returns immediately (return) once the matching tag is found, rather than using break (which previously required an additional check after the loop).
  4. Relaxes the nil-check on the response — an empty Tags slice is now valid (last page) and no longer triggers a non-retryable error.

Steps to Reproduce

  1. Create an account or project with more tags than the GetTags API returns per page.
  2. Manage a tag near the end of the list with Terraform using the tencentcloud_tag resource.
  3. Run terraform plan — Terraform will report the tag resource needs to be re-created even though it already exists.

References

  • Affected file: tencentcloud/services/tag/service_tencentcloud_tag.go
  • Affected function: DescribeTagResourceById
  • Tencent Cloud API: GetTags

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions