Skip to content

Conversation

@KshitijaChoudhari
Copy link
Collaborator

@KshitijaChoudhari KshitijaChoudhari commented Dec 12, 2025

Summary

This PR adds comprehensive support for Terraform Cloud Workspace Run Tasks, enabling users to attach, manage, and configure run tasks at the workspace level.

Changes

New Files

  • src/pytfe/models/workspace_run_task.py: Pydantic models for workspace run tasks including:

    • WorkspaceRunTask: Main model with relationships to workspace and run task
    • WorkspaceRunTaskCreateOptions: Model for creating workspace run task associations
    • WorkspaceRunTaskUpdateOptions: Model for updating enforcement level and stage
    • WorkspaceRunTaskList: Pagination support for listing workspace run tasks
    • WorkspaceRunTaskListOptions: Query parameters for filtering and pagination
  • src/pytfe/resources/workspace_run_task.py: Complete CRUD operations:

    • list(): List all run tasks attached to a workspace with pagination
    • read(): Get details of a specific workspace run task
    • create(): Attach a run task to a workspace with enforcement level and stage
    • update(): Modify enforcement level or stage of an existing workspace run task
    • delete(): Remove a run task from a workspace
  • tests/units/test_workspace_run_task.py: Comprehensive test coverage (20 tests):

    • CRUD operation tests with proper mocking
    • Validation tests for IDs and parameters
    • Pagination and filtering tests
    • Error handling tests
  • examples/workspace_run_task.py: Complete example demonstrating all operations

Modified Files

  • src/pytfe/models/run_task.py:

    • Fixed Stage enum values to use underscores instead of hyphens (pre_plan, post_plan, pre_apply, post_apply)
    • Added workspace_run_tasks relationship to RunTask model
    • Implemented TYPE_CHECKING pattern to resolve circular import with workspace_run_task
  • src/pytfe/resources/run_task.py: Added parsing for workspace_run_tasks relationship

  • src/pytfe/client.py: Registered workspace_run_tasks service

  • src/pytfe/models/init.py: Exported workspace run task models

  • src/pytfe/errors.py: Added InvalidWorkspaceRunTaskIDError for validation

  • tests/units/test_run_task.py: Updated tests to use underscore format for Stage enum

Testing

All tests pass successfully:

  • 20 new tests for workspace run task functionality
  • 7 updated tests for run task with fixed Stage enum
  • Total: 27/27 tests passing

Quality checks:

  • Code formatting (ruff)
  • Linting (ruff)
  • Type checking (mypy)

API Compatibility

Implements the Terraform Cloud API endpoints:

  • GET /api/v2/workspaces/:id/tasks
  • GET /api/v2/workspaces/:id/tasks/:id
  • POST /api/v2/workspaces/:id/tasks
  • PATCH /api/v2/workspaces/:id/tasks/:id
  • DELETE /api/v2/workspaces/:id/tasks/:id

Breaking Changes

  • Stage enum values changed from hyphenated format (pre-plan) to underscore format (pre_plan) to match Terraform Cloud API specifications

- Add WorkspaceRunTask models and resources
- Add WorkspaceRunTasks service with CRUD operations
- Update RunTask model to include workspace_run_tasks relationship
- Fix Stage enum to use underscore format (pre_plan, post_plan, etc.)
- Add comprehensive unit tests (20 tests)
- Add example CLI for workspace run task operations
- Update client to include workspace_run_tasks service
@KshitijaChoudhari KshitijaChoudhari requested a review from a team as a code owner December 12, 2025 06:15
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.

1 participant