Skip to content

update Run Relationships#119

Merged
isivaselvan merged 1 commit into
hashicorp:next-0.1.3from
ibm-richard:next-0.1.3
Mar 30, 2026
Merged

update Run Relationships#119
isivaselvan merged 1 commit into
hashicorp:next-0.1.3from
ibm-richard:next-0.1.3

Conversation

@ibm-richard

Copy link
Copy Markdown
Contributor

Description

based on this issue items that aren't included in the 'attributes' part of a response were being dropped when the model is being constructed from the API response.

Testing plan

  1. I created a run in HCP Terraform and saved the run id ("run-ugBnsFDyDviC876w")
  2. I used the following code to fetch the response that the API returns
    config = TFEConfig(address="https://app.terraform.io", token=tf_api_key)
    tfe_client = TFEClient(config)
    run_id="run-ugBnsFDyDviC876w"
    options = RunReadOptions(
                include=[
                    RunIncludeOpt.RUN_PLAN,
                    RunIncludeOpt.RUN_APPLY,
                    RunIncludeOpt.RUN_CREATED_BY,
                ]
            )
    run = tfe_client.runs.read_with_options(run_id, options=options)
  1. I intercepted the response before we start parsing it by hot-patching the run.py file locally.
        r = self.t.request(
            "GET",
            f"/api/v2/runs/{run_id}",
            params=params,
        )
        d = r.json().get("data", {})
        #### my code bloew
        import json
        print(json.dumps(d, indent=2))
  1. I used the json reponse from the API as a test case to run the existing run-detailed-123 case and found that it failed if I added an assertion assert result.created_by.id == "user-FRJGnNMX6fpe9Cdd"

  2. updated the run.py resource to properly handle the response items that are not nested within attributes (i.e. relationships)

External links

Output from tests

(.venv) richardboyd@Richards-MBP python-tfe % python -m pytest tests/units/test_run.py -v
===================================================================== test session starts ======================================================================
platform darwin -- Python 3.14.2, pytest-9.0.2, pluggy-1.6.0 -- /Users/richardboyd/Developer/python-tfe/.venv/bin/python
cachedir: .pytest_cache
rootdir: /Users/richardboyd/Developer/python-tfe
configfile: pyproject.toml
plugins: anyio-4.12.1, mock-3.15.1
collected 12 items                                                                                                                                             

tests/units/test_run.py::TestRuns::test_list_runs_success PASSED                                                                                         [  8%]
tests/units/test_run.py::TestRuns::test_list_for_organization_success PASSED                                                                             [ 16%]
tests/units/test_run.py::TestRuns::test_create_run_validation_errors PASSED                                                                              [ 25%]
tests/units/test_run.py::TestRuns::test_create_run_success PASSED                                                                                        [ 33%]
tests/units/test_run.py::TestRuns::test_read_run_validation_errors PASSED                                                                                [ 41%]
tests/units/test_run.py::TestRuns::test_read_run_success PASSED                                                                                          [ 50%]
tests/units/test_run.py::TestRuns::test_read_with_options_success PASSED                                                                                 [ 58%]
tests/units/test_run.py::TestRuns::test_apply_run_success PASSED                                                                                         [ 66%]
tests/units/test_run.py::TestRuns::test_cancel_run_success PASSED                                                                                        [ 75%]
tests/units/test_run.py::TestRuns::test_force_cancel_run_success PASSED                                                                                  [ 83%]
tests/units/test_run.py::TestRuns::test_force_execute_run_success PASSED                                                                                 [ 91%]
tests/units/test_run.py::TestRuns::test_discard_run_success PASSED                                                                                       [100%]

====================================================================== 12 passed in 0.23s ======================================================================

Rollback Plan

N/A

Changes to Security Controls

N/A

PCI review checklist

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

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

  • [N/A] 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.

@ibm-richard ibm-richard requested a review from a team as a code owner March 20, 2026 14:51
@ibm-richard

Copy link
Copy Markdown
Contributor Author

I force-pushed an update to keep the run-id consistent throughout the API response.

@isivaselvan isivaselvan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you @ibm-richard for contributing to our repo. The code for relationship mapping looks good and it's working. LGTM!

@isivaselvan isivaselvan merged commit 75bbefd into hashicorp:next-0.1.3 Mar 30, 2026
11 checks passed
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