Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion examples/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,32 @@ def main():
except Exception as e:
print(f"Error reading run details: {e}")

# 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 ?


print("Available Run Source types and their meanings:")
print(
f"- {RunSource.Run_Source_API.value}: Runs created via Terraform Enterprise/Cloud API"
)
print(
f"- {RunSource.Run_Source_Configuration_Version.value}: Runs triggered by VCS configuration version uploads"
)
print(f"- {RunSource.Run_Source_UI.value}: Runs created via Terraform Cloud UI")
print(
f"- {RunSource.Run_Source_Terraform_Cloud.value}: Runs from Terraform CLI with cloud backend"
)
print(f"- {RunSource.Run_Source_Terraform.value}: Runs from Terraform CLI")
print(
f"- {RunSource.Run_Source_Run_Trigger.value}: Runs triggered by run triggers"
)
print(
f"- {RunSource.Run_Source_Infra_Lifecycle.value}: Runs from infrastructure lifecycle events"
)
print()
print("The SDK now supports all these run source types for proper validation.")

# 3) Optionally create a new run
if args.create_run:
_print_header("Creating a new plan-only run")
Expand Down Expand Up @@ -218,7 +244,7 @@ def main():
print("No runs available for actions demo")
return

demo_run = run_list.items[0]
demo_run = run_list[0]
print(f"Demonstrating actions for run: {demo_run.id}")
print(f"Current status: {demo_run.status}")

Expand Down
3 changes: 3 additions & 0 deletions src/pytfe/models/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class RunSource(str, Enum):
Run_Source_Configuration_Version = "tfe-configuration-version"
Run_Source_UI = "tfe-ui"
Run_Source_Terraform_Cloud = "terraform+cloud"
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.


class RunStatus(str, Enum):
Expand Down
34 changes: 34 additions & 0 deletions tests/units/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,3 +417,37 @@ def test_discard_run_success(self, runs_service):
assert call_args[0][0] == "POST"
assert call_args[0][1] == "/api/v2/runs/run-discard-123/actions/discard"
assert call_args[1]["json_body"]["comment"] == "Discarding run"

def test_run_source_enum_values(self):
"""Test that all RunSource enum values work with Run model validation."""

# Test all RunSource enum values
test_sources = [
("tfe-api", RunSource.Run_Source_API),
("tfe-configuration-version", RunSource.Run_Source_Configuration_Version),
("tfe-ui", RunSource.Run_Source_UI),
("terraform+cloud", RunSource.Run_Source_Terraform_Cloud),
("terraform", RunSource.Run_Source_Terraform),
("tfe-run-trigger", RunSource.Run_Source_Run_Trigger),
("tfe-infrastructure-lifecycle", RunSource.Run_Source_Infra_Lifecycle),
]

for source_value, expected_enum in test_sources:
# Test that Run model can be created with this source
# Use the same format as the service methods (attributes flattened with id)
run_data = {
"id": f"run-test-{source_value.replace('+', '').replace('-', '_')}",
"status": "pending",
"source": source_value,
"message": f"Test run with source {source_value}",
"created-at": "2023-01-01T12:00:00Z",
"has-changes": False,
"is-destroy": False,
}

# This should not raise an exception
run = Run.model_validate(run_data)

# Verify the source was correctly parsed
assert run.source == expected_enum
assert run.source.value == source_value
Loading