Skip to content

Refactor/project create update models#120

Open
isivaselvan wants to merge 2 commits intonext-0.1.3from
refactor/project-create-update-models
Open

Refactor/project create update models#120
isivaselvan wants to merge 2 commits intonext-0.1.3from
refactor/project-create-update-models

Conversation

@isivaselvan
Copy link
Collaborator

@isivaselvan isivaselvan commented Mar 24, 2026

Description

This PR refactors the Project resource/models to align with current API payload/response structure, rewrites the project example into a CLI workflow, and updated unit tests.

Changes

  1. Project model refactor
  • Updated project.py to use alias-aware Pydantic mapping for API fields.

  • Expanded Project fields to include:

    • auto destroy activity duration
    • setting overwrites
    • default agent pool relationship
    • organization as a structured model (not plain string)
  • Extended create/update option models with:

    • default execution mode
    • default agent pool id
    • setting overwrites
    • tag bindings
  • Added and exported ProjectSettingOverwrites from init.py

  1. Projects resource refactor
  • Updated projects.py validation to accept full create/update option objects.
  • Added agent-mode guard:
    • when execution mode is agent, default agent pool id is required.
  • Refactored create/update payload building using model-driven dumps and relationship handling for tag bindings/setting overwrites.
  • Unified response parsing through _project_from helper for list/create/read/update.
  • Added relationship parsing for organization and default agent pool in _project_from.
  • Updated effective tag bindings endpoint to:
    • GET /projects/{id}/effective-tag-bindings
  • Updated delete tag bindings flow to clear relationships using:
    • PATCH /projects/{id} with empty tag-bindings relationship data.
  1. Project example rewrite
  • Replaced the old integration-test style example with a CLI-driven example in project.py
  • Added command-based flows for:
    • list, create, read, update, delete
    • list/add/delete tag bindings
    • list effective tag bindings
  • Added argument parsing, env var support, input validation, and formatted output.
  1. Test updates
  • Updated project unit tests in test_project.py to match:
    • new organization model behavior
    • new create/update payload shape
    • updated effective/delete tag-binding API behavior
  • Updated workspace unit setup in test_workspaces.py for Project model compatibility.
  • Removed placeholder organization injection in variable set parsing in variable_sets.py to avoid invalid nested model values.

Testing plan

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.

Unit tests

image

Examples

> python examples/project.py --list

================================================================================
Listing projects for organization: prab-sandbox01
================================================================================
- Default Project (ID: prj-VqLp)
  Description: None
  Workspaces: 38
  Default execution mode: remote
  Auto destroy activity duration: None
  Created at: 2025-09-05T06:19:17.830Z
  Updated at: None
  Setting overwrites: execution_mode=True agent_pool=True
  Default agent pool: None
  Organization: sandbox01

- hello-tf (ID: prj-fC61Au)
  Description: 
  Workspaces: 0
  Default execution mode: remote
  Auto destroy activity duration: None
  Created at: 2025-09-16T08:04:11.808Z
  Updated at: None
  Setting overwrites: execution_mode=False agent_pool=False
  Default agent pool: None
  Organization: sandbox01


> python examples/project.py --create --name sdk-create-test --description "Created from examples/project.py" --create-random

================================================================================
Creating project: sdk-create-test-9bcf87bb
================================================================================
Created project: prj-RwUYE9rRZi
Name: sdk-create-test-9bcf87bb
Description: Created from examples/project.py
Workspaces: 0
Default execution mode: remote
Auto destroy activity duration: None
Created at: 2026-03-24T17:25:10.532Z
Updated at: None
Setting overwrites: execution_mode=False agent_pool=False
Default agent pool: None
Organization: sandbox01


> python examples/project.py --read --project-id=prj-Hci3dayB

================================================================================
Reading project: prj-Hci3dayB
================================================================================
ID: prj-Hci3dayB
Name: testprojupdation
Description: new try again
Organization: prab-sandbox01
Created at: 2026-03-10T07:17:19.856Z
Updated at: None
Workspace count: 0
Default execution mode: remote
Auto destroy activity duration: None


> python examples/project.py --update --project-id=prj-RwnRZi  --name=testprojupdationtest

================================================================================
Updating project: prj-Rwn9rRZi
================================================================================
Project updated successfully
ID: prj-RwnrRZi
Name: testprojupdationtest
Description: Created from examples/project.py


> python examples/project.py --add-tag-bindings --project-id=prj-Rwn9rRZi  --tag 'test=project' 

================================================================================
Adding tag bindings to project: prj-RwE9rRZi
================================================================================
- test=project
Total returned: 1 tag bindings

> python examples/project.py --list-tag-bindings --project-id=prj-Rw9rRZi 

================================================================================
Listing tag bindings for project: prj-RwnXPHTnUYE9rRZi
================================================================================
- test=project
Total: 1 tag bindings


> python-tfe % python examples/project.py --list-effective-tag-bindings --project-id=prj-RwnXE9rRZi

================================================================================
Listing effective tag bindings for project: prj-RwnXE9rRZi
================================================================================
- test=project
Total: 1 effective tag bindings


> python examples/project.py --delete-tag-bindings --project-id=prj-RwnRZi

================================================================================
Deleting all tag bindings from project: prj-RwnXZi
================================================================================
Deleted all project tag bindings


> python-tfe % python examples/project.py --delete --project-id=prj-RwnYE9rRZi 

================================================================================
Deleting project: prj-RwnXE9rRZi
================================================================================
Project deleted successfully

Rollback Plan

Changes to Security Controls

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.

…he endpoint for list-effective-tag-bindings & delete-tag-bindings and added new examples for project
@isivaselvan isivaselvan requested a review from a team as a code owner March 24, 2026 09: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.

1 participant