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:
- Sets
request.MaxResults = 1000 to request the maximum number of results per page.
- Wraps the
GetTags call in a for loop that follows PaginationToken until all pages are exhausted.
- Returns immediately (
return) once the matching tag is found, rather than using break (which previously required an additional check after the loop).
- 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
- Create an account or project with more tags than the
GetTags API returns per page.
- Manage a tag near the end of the list with Terraform using the
tencentcloud_tag resource.
- 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
Community Note
Bug:
DescribeTagResourceByIdfails to find tags when more than 50 tag entries existSummary
DescribeTagResourceByIdinservice_tencentcloud_tag.gouses theGetTagsAPI 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 setsMaxResultsto 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
GetTagsonce and iterated over the results. Because noMaxResultswas set andPaginationTokenwas never used, the function only ever checked the first page of results. If the target tag existed beyond the first page,tagReswould remainnil— 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
Tagswas an empty slice (e.g. on subsequent pages that exhaust results), which could cause false negatives.Impact
tencentcloud_tagresource does not exist.terraform plan/applyruns.Fix
The fix in
service_tencentcloud_tag.go:request.MaxResults = 1000to request the maximum number of results per page.GetTagscall in aforloop that followsPaginationTokenuntil all pages are exhausted.return) once the matching tag is found, rather than usingbreak(which previously required an additional check after the loop).Tagsslice is now valid (last page) and no longer triggers a non-retryable error.Steps to Reproduce
GetTagsAPI returns per page.tencentcloud_tagresource.terraform plan— Terraform will report the tag resource needs to be re-created even though it already exists.References
tencentcloud/services/tag/service_tencentcloud_tag.goDescribeTagResourceByIdGetTags