Skip to content

feature: Add ListOrganizations & GetOrganizationDetails tfe tools #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: feature/tfenterprise-long-lived
Choose a base branch
from

Conversation

aditya2548
Copy link
Contributor

Changes

  • Introduced the initial package structure for Enterprise Tools.
  • Added support for the HCP_TFE_TOKEN and HCP_TFE_ADDRESS environment variables.
  • Implemented the following Terraform Enterprise organization tools:
    • ListOrganizations
    • GetOrganizationDetails
  • Note: Updates to end-to-end (e2e) tests to reflect these changes will be included in a separate PR.
  • Clients can invoke these tools sequentially to retrieve relevant organization data. For example:
Screenshot 2025-05-19 at 15 57 38

Copy link
Collaborator

@BBBmau BBBmau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested this locally, it works great however I can't truly test the pagination feature which is where my comments are coming from.

allOrgs = append(allOrgs, orgList.Items...)
totalCount = orgList.TotalCount

if len(allOrgs) >= totalCount || len(orgList.Items) == 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it necessary to check len(allOrgs) >= totalCount? Wouldn't this always trigger on the first iteration since we are comparing the totalCount of the list with the same length list of orgList.Items?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

len(allOrgs) >= totalCount is used to determine when we've collected all organizations across paginated responses. Since orgList.Items only contains the current page's results, we need to track the total across all pages. This check ensures we stop once we've fetched everything based on the totalCount value returned by the API.

The len(orgList.Items) == 0 check is an additional safeguard in case the API doesn't return the full count or if something unexpected happens (like a partial page).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah okay so allOrgs just represents what's on the page while totalCount is the total organization count across all pages.

Can we include a comment on this or maybe rename to be clearer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated variable names to make it clearer.

@aditya2548 aditya2548 changed the title Add ListOrganizations & GetOrganizationDetails tfe tools feature: Add ListOrganizations & GetOrganizationDetails tfe tools May 21, 2025
pageNumber := 1
totalCount := 0

// Iterate through all pages to collect all organizations
Copy link
Collaborator

@BBBmau BBBmau May 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be done in a separate PR but we should look into how we can have single pagination implementation for use across all tools since I imagine we'll be running into pagination constantly.

Edit: created a issue here

@aditya2548 aditya2548 requested a review from BBBmau May 26, 2025 06:46
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.

None yet

2 participants