Skip to content

Conversation

@KshitijaChoudhari
Copy link
Collaborator

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

What's Changed

New Functionality:

  • Complete CRUD operations for workspace run tasks (list, read, create, update, delete)
  • Pydantic models with full type safety and validation
  • Support for pagination, filtering, and relationship parsing
  • Enforcement level and stage configuration

Bug Fixes:

  • Fixed Stage enum in run_task model to use underscores (pre_plan, post_plan, pre_apply, post_apply) instead of hyphens to match Terraform Cloud API specifications
  • Resolved circular import between run_task and workspace_run_task using TYPE_CHECKING pattern

New Files:

  • src/pytfe/models/workspace_run_task.py
  • src/pytfe/resources/workspace_run_task.py
  • tests/units/test_workspace_run_task.py
  • examples/workspace_run_task.py

Modified Files:

  • src/pytfe/models/run_task.py (Stage enum fix, added workspace_run_tasks relationship)
  • src/pytfe/resources/run_task.py (relationship parsing)
  • src/pytfe/client.py (service registration)
  • src/pytfe/models/init.py (model exports)
  • src/pytfe/errors.py (new error class)
  • tests/units/test_run_task.py (updated for Stage enum)

Testing plan

  1. Unit Tests (27/27 passing):

    • Run `pytest tests/units/test_workspace_run_task.py tests/units/test_run_task.py -v`
    • Covers all CRUD operations, validation, pagination, error handling
  2. Code Quality:

    • All checks pass on 141 files
  3. Example Usage:

    • See `examples/workspace_run_task.py` for complete working example
    • Tested against real Terraform Cloud API

External links

Output from tests

pytest tests/units/test_workspace_run_task.py tests/units/test_run_task.py -v
========================= test session starts ==========================
collected 27 items

test_workspace_run_task_list PASSED
test_workspace_run_task_list_with_options PASSED
test_workspace_run_task_list_with_pagination PASSED
test_workspace_run_task_list_empty PASSED
test_workspace_run_task_read PASSED
test_workspace_run_task_read_with_includes PASSED
test_workspace_run_task_create PASSED
test_workspace_run_task_create_with_all_options PASSED
test_workspace_run_task_update PASSED
test_workspace_run_task_update_enforcement_level PASSED
test_workspace_run_task_update_stage PASSED
test_workspace_run_task_delete PASSED
test_workspace_run_task_list_invalid_workspace_id PASSED
test_workspace_run_task_read_invalid_workspace_id PASSED
test_workspace_run_task_read_invalid_id PASSED
test_workspace_run_task_create_invalid_workspace_id PASSED
test_workspace_run_task_update_invalid_workspace_id PASSED
test_workspace_run_task_update_invalid_id PASSED
test_workspace_run_task_delete_invalid_workspace_id PASSED
test_workspace_run_task_delete_invalid_id PASSED
test_run_task_create PASSED
test_run_task_list PASSED
test_run_task_read PASSED
test_run_task_update PASSED
test_run_task_update_url PASSED
test_run_task_delete PASSED
test_run_task_attach_to_workspace PASSED

========================= 27 passed in 0.29s ===========================
141 files already formatted
All checks passed!
Success: no issues found in 86 source files

Rollback Plan

If this change needs to be reverted, we will:

  1. Remove the new workspace_run_task module files
  2. Revert the Stage enum changes in run_task.py (though this may break compatibility with Terraform Cloud API)
  3. Roll out a patch release within 7 days if critical issues are discovered

Changes to Security Controls

No changes to security controls. This PR adds new API resource management functionality using the existing authentication and authorization mechanisms."

PCI review checklist

  • I have documented a clear reason for, and description of, the change I am making.

  • If applicable, I've documented a plan to revert these changes if they require more than reverting the pull request.

  • If applicable, I've documented the impact of any changes to security controls.

    Examples of changes to security controls include using new access control methods, adding or removing logging pipelines, etc.

If you have any questions, please contact your direct supervisor, GRC (#team-grc), or the PCI working group (#proj-pci-reboot). You can also find more information at PCI Compliance.

@KshitijaChoudhari KshitijaChoudhari requested a review from a team as a code owner December 12, 2025 07:37
@KshitijaChoudhari KshitijaChoudhari changed the title Feat/workspace run task feat(workspace-run-task): add workspace run task support Dec 12, 2025
aayushsingh2502 and others added 8 commits December 15, 2025 11:16
- Add WorkspaceResource model and WorkspaceResourceListOptions
- Add WorkspaceResourcesService for listing workspace resources
- Add workspace_resources.py example CLI tool with flag-based interface
- Add comprehensive unit tests for workspace resources
- Update client.py to include workspace_resources service
- Update models/__init__.py with WorkspaceResource exports
- Remove urllib.parse import
- Remove URL encoding for workspace_id parameter
- Workspace IDs are alphanumeric with hyphens, no encoding needed
- Consistent with other services in the codebase
- Remove test_list_workspace_resources_url_encoding test
- URL encoding is not needed for workspace IDs
- All 376 tests now passing
- 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
Copy link
Collaborator Author

Rebase for this PR was not successful hence closing this PR

@KshitijaChoudhari
Copy link
Collaborator Author

Rebase for this PR wasn't successful hence closing this PR

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