Skip to content

🚀 Add Explorer API (v2) support to pytfe - #136

Merged
isivaselvan merged 6 commits into
hashicorp:next-1.0.0from
jasodeep:main
May 13, 2026
Merged

🚀 Add Explorer API (v2) support to pytfe#136
isivaselvan merged 6 commits into
hashicorp:next-1.0.0from
jasodeep:main

Conversation

@jasodeep

Copy link
Copy Markdown
Contributor

📌 Description

This PR adds support for the HCP Terraform / Terraform Enterprise Explorer API (v2) to pytfe, exposed via:

TFEClient.explorer

The Explorer API enables organization-scoped visibility and analytics, including:

  • Workspaces
  • Terraform versions
  • Registry providers
  • Modules

It also supports:

  • CSV export
  • Saved views (CRUD operations)
  • Re-running saved views (JSON / CSV)

This implementation covers public v2 routes under:

/api/v2/organizations/:organization/explorer
/api/v2/organizations/:organization/explorer/views/*

✨ Changes Included

📦 Models

  • Added new Pydantic models:

    • src/pytfe/models/explorer.py
  • Exported models via:

    • src/pytfe/models/__init__.py

🔧 Resources

  • Added new resource:

    • Explorersrc/pytfe/resources/explorer.py
  • Pagination aligned with existing _Service patterns

🧠 Client

  • Added:

    TFEClient.explorer

    in src/pytfe/client.py

❗ Errors

  • Introduced:

    • InvalidExplorerSavedViewIDError in src/pytfe/errors.py

🧪 Tests

  • Added unit tests with mocked HTTP:

    • tests/units/test_explorer.py

📘 Examples

  • Added usage example:

    • examples/explorer.py

📝 Changelog

  • Updated:

    • CHANGELOG.md under v0.2.0 (Unreleased)

🧪 Testing Plan

🔹 Local (No live cluster)

make dev-install   # Python ≥ 3.10
make check
make test

🔹 Optional (Live HCP Terraform / TFE)

Set environment variables:

export TFE_ADDRESS=<your-address>
export TFE_TOKEN=<your-token>
export TFE_ORGANIZATION=<your-org>

Run:

python examples/explorer.py

Optional (Saved View flows)

export TFE_EXPLORER_VIEW_ID=<view-id>
export TFE_EXPLORER_DEMO_MUTATIONS=1

⚠️ This will perform create/update/delete operations on a uniquely named view.

Ensure:

  • Token has required Explorer API permissions
  • Organization access is valid

🔄 Rollback Plan

  • Revert this PR from main

  • Removes:

    • client.explorer
    • Explorer models/resources/tests

✅ No infra or migration rollback required


🔐 Changes to Security Controls

  • No changes in this repository

  • Authentication:

    • Uses existing HTTPTransport + bearer token
  • Authorization:

    • Enforced by HCP Terraform / TFE APIs

✅ PCI Review Checklist

  • Clear description and justification provided
  • Rollback plan documented (PR revert sufficient)
  • No changes to security controls

🧾 CONTRIBUTING Checklist

  • Code formatted (make fmt)
  • Lint passes (make lint)
  • Type checks pass (make type-check)
  • Tests pass (make test)
  • Unit tests added for new functionality
  • CHANGELOG.md updated
  • Example added under examples/
  • Docstrings added for public classes/methods

@jasodeep
jasodeep requested a review from a team as a code owner April 24, 2026 19:10
@hashicorp-cla-app

hashicorp-cla-app Bot commented Apr 24, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Comment thread src/pytfe/resources/explorer.py
Comment thread src/pytfe/models/explorer.py Outdated
Comment thread src/pytfe/resources/explorer.py Outdated
- Unused TYPE is removed.
- CSV header order fixed as per API response.

@rigalGit rigalGit left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good, please check some minor comments.

Comment thread tests/units/test_explorer.py Outdated
Comment thread src/pytfe/resources/explorer.py Outdated
Comment thread src/pytfe/resources/explorer.py
Comment thread src/pytfe/resources/explorer.py Outdated
Comment thread tests/units/test_explorer.py Outdated
@jasodeep
jasodeep requested a review from rigalGit April 28, 2026 11:38
@isivaselvan
isivaselvan merged commit d15ba17 into hashicorp:next-1.0.0 May 13, 2026
11 checks passed
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.

3 participants