Skip to content

Add missing RunSource enum values for runs.list_for_organization#121

Closed
KshitijaChoudhari wants to merge 1 commit intonext-0.1.3from
bug/run_sources
Closed

Add missing RunSource enum values for runs.list_for_organization#121
KshitijaChoudhari wants to merge 1 commit intonext-0.1.3from
bug/run_sources

Conversation

@KshitijaChoudhari
Copy link
Copy Markdown
Collaborator

@KshitijaChoudhari KshitijaChoudhari commented Mar 30, 2026

  • Add terraform, tfe-run-trigger, and tfe-infrastructure-lifecycle sources
  • Add comprehensive unit tests for all RunSource enum values
  • Update example file to demonstrate all run source types
  • Fix bug in example file list indexing
  • Apply proper code formatting

Description

This PR adds missing RunSource enum values to support all run sources returned by the Terraform Cloud API. The runs.list_for_organization method was failing to retrieve runs with certain source types due to incomplete enum definitions.

Motivation and Context
The runs.list_for_organization method was failing when encountering runs with source values like "terraform", "tfe-run-trigger", and "tfe-infrastructure-lifecycle" because these weren't defined in the RunSource enum. This caused Pydantic validation errors when the API returned runs with these source types, preventing users from listing all runs in their organization.

Type of Change
Bug fix (non-breaking change which fixes an issue)
New feature (non-breaking change which adds functionality)

Changes Made
Change 1: Enhanced RunSource enum with missing values

Added Run_Source_Terraform = "terraform" for Terraform CLI runs
Added Run_Source_Run_Trigger = "tfe-run-trigger" for run trigger initiated runs
Added [Run_Source_Infra_Lifecycle = "tfe-infrastructure-lifecycle" for infrastructure lifecycle runs
This ensures complete coverage of all run sources returned by the Terraform Cloud API

Change 2: Added comprehensive unit tests

Created test_run_source_enum_values()
Tests all 7 RunSource enum values to ensure proper validation
Validates that Run model accepts all source types without errors

Change 3: Updated example file with demonstrations

Added RunSource import to run.py
Added "Run Source Types Demonstration" section showing all source types with descriptions
Fixed bug in run actions demo where run_list.items[0] should be run_list[0]

Implementation Details -
Architecture Changes
No architectural changes. This is an enhancement to the existing RunSource enum to support additional API values.

Key Files Changed
run.py : Added 3 new RunSource enum values for complete API coverage

test_run.py = Added comprehensive test coverage for all RunSource enum values
run.py = Updated imports, added demonstration section, and fixed list indexing bug

Testing plan

Unit Tests: All 13 run unit tests pass (including new test for enum values)

Code Quality: Formatting (Ruff), linting, and type checking all pass
Validation: Confirmed that Run model now accepts all 7 run source types without validation errors
Screenshots/Recordings
N/A - This is a backend/model enhancement with no UI changes.

External links

-->

Output from tests

Including output from tests may require access to a TFE instance. Ignore this section if you have no environment to test against.

Integration Tests: All 445 unit tests across the codebase pass

Screenshot 2026-03-30 at 11 11 39 AM Screenshot 2026-03-30 at 11 12 15 AM

Unit Tests: All 13 run unit tests pass (including new test for enum values)

Screenshot 2026-03-30 at 11 12 29 AM

Breaking Changes

No breaking changes. This is a backward-compatible enhancement that adds support for previously unsupported run source types. Existing code will continue to work as before, but now runs.list_for_organization will successfully retrieve all runs regardless of their source type.

Rollback Plan

No changes to security controls. This PR only adds missing enum values to support additional run source types returned by the Terraform Cloud API. There are no modifications to:

Access controls
Authentication/authorization logic
Encryption mechanisms
Logging functionality
Input validation (beyond expanding the allowed enum values)
Network security
Data handling

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.

- Add terraform, tfe-run-trigger, and tfe-infrastructure-lifecycle sources
- Add comprehensive unit tests for all RunSource enum values
- Update example file to demonstrate all run source types
- Fix bug in example file list indexing
- Apply proper code formatting
@KshitijaChoudhari KshitijaChoudhari requested a review from a team as a code owner March 30, 2026 06:47
Comment thread src/pytfe/models/run.py
Run_Source_Terraform = "terraform"
Run_Source_Run_Trigger = "tfe-run-trigger"
Run_Source_Infra_Lifecycle = "tfe-infrastructure-lifecycle"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comment thread examples/run.py
# Demonstrate RunSource enum values
_print_header("Run Source Types Demonstration")

from pytfe.models.run import RunSource
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not getting this change ? We are printing that everything is working without directly using it ?

@iam404 iam404 closed this Apr 1, 2026
@iam404 iam404 deleted the bug/run_sources branch April 1, 2026 07:53
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.

2 participants