Skip to content

Add TaskStage API support with models, resource, tests and examples#148

Closed
TanyaSingh369-svg wants to merge 16 commits into
next-1.0.0from
feature/task-stage-api
Closed

Add TaskStage API support with models, resource, tests and examples#148
TanyaSingh369-svg wants to merge 16 commits into
next-1.0.0from
feature/task-stage-api

Conversation

@TanyaSingh369-svg

@TanyaSingh369-svg TanyaSingh369-svg commented May 8, 2026

Copy link
Copy Markdown
Contributor

Description

This PR adds support for Task Stages APIs in the Python TFE client, aligned with the go-tfe implementation.

Task stages represent different phases of a Terraform run and capture execution status, policy checks, and run task results. This PR enables users to retrieve a task stage by ID, list task stages for a run, and override a task stage when permitted.

The implementation follows existing repository patterns for resources and models, and includes proper handling of relationships and forward references between TaskStage, TaskResult, and PolicyEvaluation to avoid circular dependencies.

Changes

  • Implemented TaskStages resource with the following methods:
    • read() – Retrieve a task stage by ID
    • list() – List all task stages associated with a run
    • override() – Override a task stage when permissions allow
  • Added corresponding models:
    • TaskStage
    • TaskResult
    • Added supporting enums and nested models:
      - Stage
      - TaskStageStatus
      - TaskStageStatusTimestamps
      - Permissions
      - Actions
      - TaskResultStatus
      - TaskResultStatusTimestamps
      - TaskEnforcementLevel
  • Implemented relationships between models (e.g., task results and policy evaluations within a task stage)
  • Updated TFEClient to expose the task_stages service
  • Added example (examples/task_stage_example.py) demonstrating:
    • Fetching a task stage by ID
    • Listing task stages for a given run
    • Overriding a task stage

Testing

  • Added unit tests for TaskStages resource:
    - Verified service availability on the client
    - Verified method presence (read, list, override)
    - Tested validation for invalid inputs (e.g., missing or invalid IDs)
    - Mocked HTTP transport layer to validate request construction and payloads
    - Verified override behavior with and without optional comment
  • Ensured:
    - All unit tests pass successfully (pytest)
    - Code formatting and linting checks pass (ruff, mypy)
  • Manually tested functionality using a real Task Stage ID:
    - Successfully retrieved task stage details via read()
    - Verified response fields and structure match expected API output

Output

Run the unit test
Screenshot 2026-05-22 at 2 05 48 PM

Run the examples

Screenshot 2026-05-21 at 10 47 46 PM Screenshot 2026-05-21 at 10 47 09 PM

@TanyaSingh369-svg TanyaSingh369-svg requested a review from a team as a code owner May 8, 2026 08:13
Comment thread examples/task_stage_example.py
Comment thread src/pytfe/models/task_stage.py Outdated
Comment thread src/pytfe/models/task_stage.py Outdated
Comment thread src/pytfe/resources/task_stage.py
Comment thread src/pytfe/models/task_stage.py Outdated

stage: Stage = Field(..., alias="stage")

status: TaskStageStatus = Field(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Currently most of attributes at TaskStage were mandatory, Could make id as only mandatory attribute in the TaskStage. So, the model will be utilized as Stub in relationship for other models.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated TaskStage model so only id is required and remaining fields are optional for relationship stub usage.

Comment thread src/pytfe/resources/task_stage.py Outdated
# Read
def read(self, task_stage_id: str) -> TaskStage:
if not valid_string_id(task_stage_id):
raise ValueError("Invalid task_stage_id")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Create an error InvalidTaskStageID in the errors.py

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added InvalidTaskStageIDError in errors.py.

Comment thread src/pytfe/resources/task_stage.py
Comment thread src/pytfe/models/task_stage.py Outdated
TaskStage.model_rebuild(
raise_errors=False,
_types_namespace={
"TaskResult": TaskResult,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Run model was missed out at the model_rebuild

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added Run to TaskStage.model_rebuild() namespace.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

still missing

Comment thread src/pytfe/models/task_stage.py
@iam404

iam404 commented May 23, 2026

Copy link
Copy Markdown
Member

Is this still open to merge for the release ? or else we can close this. @TanyaSingh369-svg

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