-
Notifications
You must be signed in to change notification settings - Fork 1
feat(resources): add workspace resources and workspace run tasks func… #56
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
KshitijaChoudhari
wants to merge
10
commits into
next-0.1.1
Choose a base branch
from
kshitija/WorkspaceRunTasksAndWorkspaceResources
base: next-0.1.1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat(resources): add workspace resources and workspace run tasks func… #56
KshitijaChoudhari
wants to merge
10
commits into
next-0.1.1
from
kshitija/WorkspaceRunTasksAndWorkspaceResources
+2,015
−24
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…tionality - Add comprehensive workspace resources service with list operations - Implement full CRUD workspace run tasks service - Add stage enum conversion handling (snake_case ↔ kebab-case) - Create complete data models with Pydantic validation - Add 36 comprehensive unit tests with 100% coverage - Include working example applications with CLI interfaces - Maintain backward compatibility with existing pagination - Support for all execution stages and enforcement levels
|
Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement Learn more about why HashiCorp requires a CLA and what the CLA includes Have you signed the CLA already but the status is still pending? Recheck it. |
- Format examples/workspace_resources.py and src/pytfe/resources/workspace_resources.py - Ensure compliance with ruff formatting standards
- Corrected Stage enum to use kebab-case values (pre-plan, post-plan, etc.) - Moved Stage and TaskEnforcementLevel back to run_task.py where they belong - Updated workspace_run_task.py to import these enums from run_task.py - Removed unnecessary stage conversion logic in workspace_run_tasks.py service - Removed unnecessary stage conversion logic in run_task.py service - Updated test assertions to expect kebab-case stage values - All 365 tests passing, lint checks passing, type checks passing
isivaselvan
reviewed
Dec 2, 2025
…CreateOptions - Add RunTaskRelationship and RunTaskRelationshipData Pydantic models - Update WorkspaceRunTaskCreateOptions to use RunTaskRelationship instead of dict - Update service to serialize relationship using model_dump() - Add workspace run tasks relationship parsing in run_task resource - Update all tests and examples to use new relationship models - Export new models in __init__.py All tests passing (407/407), formatting and type checking clean.
- WorkspaceRunTaskCreateOptions now accepts RunTask object directly - Service layer extracts ID from RunTask object to build JSON:API relationship - Made RunTask fields optional (name, url, category, enabled) to allow minimal construction with just ID - Removed RunTaskRelationship and RunTaskRelationshipData wrapper models - Updated tests and examples to use RunTask(id='task-123') pattern - Aligns with go-tfe pattern of passing objects directly This simplifies the API - users can create RunTask(id='task-123') instead of nested relationship models.
aayushsingh2502
approved these changes
Dec 3, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…tionality
Description
Change 1: Workspace Resources Implementation↔️ kebab-case) for API compatibility
Added complete workspace resources service with list operations
Implemented proper URL encoding and parameter handling for workspace IDs
Added pagination support with comprehensive filtering options
Created robust data models with Pydantic validation
Change 2: Workspace Run Tasks Implementation
Implemented full CRUD operations (create, read, update, delete, list)
Added stage enum conversion handling (snake_case
Created comprehensive options models for all operations
Implemented proper relationship handling and include options
Change 3: Enhanced Run Task Integration
Updated existing run task service to support workspace task relationships
Added graceful Stage enum parsing for API responses
Improved error handling and validation across all operations
Change 4: Comprehensive Testing Suite
Added 36 new unit tests covering all functionality
Implemented comprehensive error scenario testing
Added model validation and data transformation tests
Maintained 100% test coverage for new functionality
Change 5: Example Applications
Created working example files with CLI interfaces
Demonstrated real-world usage with live HCP Terraform integration
Added comprehensive command-line argument handling
Implementation Details:
Architecture Changes:
Service Layer: Added WorkspaceResourcesService and WorkspaceRunTasksService following existing patterns
Model Layer: Created comprehensive Pydantic models with proper validation and field aliases
HTTP Transport: Enhanced URL construction and parameter handling for workspace-specific endpoints
Enum Handling: Implemented bidirectional Stage enum conversion for API compatibility
Key Files Changed
[workspace_resources.py]
[workspace_run_tasks.py]
[run_task.py]
[workspace_resource.py]
[workspace_run_task.py]
[init.py]
[test_workspace_resources.py]
[test_workspace_run_tasks.py]
[workspace_resources.py]
[workspace_run_tasks.py]
Testing plan
365 total tests passing (100% success rate)
36 new tests added for workspace functionality
0.51 seconds execution time - excellent performance
Zero regressions - all existing functionality maintained
Integration Testing:
Real API Testing: Successfully tested against live HCP Terraform instance
Data Handling: Verified proper parsing of real API responses
Error Scenarios: Comprehensive error handling validation
Code Quality:
Formatting: All 132 files properly formatted (Ruff)
Linting: Zero linting issues (Ruff + MyPy)
Type Safety: All 81 source files pass type checking
Standards: Full compliance with project coding standards
Example Application Results:
Workspace Resources: Successfully lists and displays 3 real resources with complete metadata
Workspace Run Tasks: Complete CLI interface with all CRUD operations functional
External links
https://developer.hashicorp.com/terraform/cloud-docs/api-docs/workspaces
https://developer.hashicorp.com/terraform/cloud-docs/workspaces/settings/run-tasks
-->
Output from tests
Listing resources for workspace:
Found 3 resource(s):
ID: wsr-xxxxxxxxxxxxxxxxx
Address: random_password.example
Name: example
Module: root
Provider: hashicorp/random
Provider Type: random_password
Created At:
Updated At:
Modified By State Version: sv-xxxxxxxxxxxxxxxxx
ID: wsr-xxxxxxxxxxxxxxxxx
Address: random_string.test
Name: test
Module: root
Provider: hashicorp/random
Provider Type: random_string
Created At:
Updated At:
Modified By State Version: sv-xxxxxxxxxxxxxxxxx
ID: wsr-xxxxxxxxxxxxxxxxx
Address: random_uuid.workspace_id
Name: workspace_id
Module: root
Provider: hashicorp/random
Provider Type: random_uuid
Created At:
Updated At:
Modified By State Version: sv-xxxxxxxxxxxxxxxxx
Pagination Info:
Current Page: 1
Total Pages: 1
Total Count: 3
Help/Usage Display:
Workspace Run Tasks Management :
options:
--org ORG Organization name
--workspace WORKSPACE Workspace ID
--create Create new workspace run task
--update Update existing workspace run task
--delete Delete workspace run task
--enforcement-level Set enforcement level (advisory|mandatory)
--stage Set execution stage (pre_plan|post_plan|pre_apply|post_apply)
List Workspace Run Tasks:
Listing Workspace Run Tasks for Workspace:
No workspace run tasks found.
Pagination Info:
Current Page: 1
Total Pages: 0
Total Count: 0
Create Workspace Run Task:
Creating Workspace Run Task
✅ Successfully created workspace run task:
Task ID:
Enforcement Level: advisory
Stage: post_plan
List After Creation:
Listing Workspace Run Tasks for Workspace:
Found 1 workspace run task(s):
Workspace Run Task ID:
Run Task ID:
Enforcement Level: advisory
Stage: post_plan
Created At:
Updated At:
Pagination Info:
Current Page: 1
Total Pages: 1
Total Count: 1
Update Workspace Run Task:
Updating Workspace Run Task:
✅ Successfully updated workspace run task
Enforcement Level: mandatory
Stage: pre_plan
Delete Workspace Run Task:
Deleting Workspace Run Task:
✅ Successfully deleted workspace run task:
Rollback Plan
If a change needs to be reverted, we will roll out an update to the code within 7 days.
-->
Changes to Security Controls
None
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.