Problem
The pagination metadata (meta.pagination
) in the response from the the Admin List All Organizations API is incorrect relative to the total number of organizations. For example, in a Terraform Enterprise instances with twenty-five organizations, a request with using default page size of twenty should receive pagination metadata reporting two total pages with a total count of twenty-five, rather than the example response below.
...
"meta": {
"pagination": {
"current-page": 1,
"prev-page": null,
"next-page": 2,
"total-pages": 3,
"total-count": 45
}
}
This will manifest in there being more pages to follow than actually contain organizations. Note that this API returns an empty JSON array for pages extending beyond the total number of organizations so it will not causing errors in clients which are configured to handle empty JSON arrays. Nevertheless, it may cause many more requests from clients than are necessary as they follow the pagination controls generated from the inaccurate total.
Prerequisites
- Terraform Enterprise >= v202406-1
- Organizations have multiple organization owners
Cause
This is a bug in Terraform Enterprise versions >=v202406-1, in which the pagination counts are inaccurately calculated over the total number of organization owners, rather than the total number of organizations. The bug is currently begin addressed by HashiCorp engineering and this article will be updated at a later time with the release in which it has been fixed.
Solution
When available, upgrade to an upcoming release of Terraform Enterprise containing the fix for this bug. In the meantime, as a workaround, implement pagination in clients which utilize this API by manually calculating the total using the meta.status-counts.active
attribute, which is an accurate representation of the total active organizations. For example, as a general guideline, use the following formula to calculate the total number of pages and continue to request pages until this total has been reached.
total_pages = ceiling(meta.status-counts.active / page_size)