Skip to content

Conversation

ctrombley
Copy link
Collaborator

@ctrombley ctrombley commented Aug 20, 2025

Description

This PR adds CanceledAt, RunEvents, TriggerReason fields to Run struct, originally by @jpadrianoGo (#1161).

Testing plan

  1. Generate the required environment variables for go test, TFE_ADDRESS and TFE_TOKEN
  2. Run TFE_ADDRESS="https://example" TFE_TOKEN="example" go test ./... -v -run TestRunsCanceledAt. The new tests should pass.
  3. CanceledAt, RunEvents, TriggerReason is read for Run.
{
  "data": {
    "id": "run-***",
    "type": "runs",
    "attributes": {
      "actions": {
        "is-cancelable": false,
        "is-confirmable": false,
        "is-discardable": false,
        "is-force-cancelable": false
      },
      "allow-config-generation": false,
      "allow-empty-apply": false,
      "auto-apply": false,
      "canceled-at": "2025-07-21T08:42:10.617Z",
      "created-at": "2025-07-21T08:42:10.116Z",
      "has-changes": false,
      "is-destroy": false,
      "message": "Triggered via API",
      "plan-only": false,
      "refresh": true,
      "refresh-only": false,
      "replace-addrs": null,
      "save-plan": false,
      "source": "tfe-api",
      "status-timestamps": {
        "force-canceled-at": "2025-07-21T08:42:10+00:00"
      },
      "status": "canceled",
      "target-addrs": null,
      "trigger-reason": "manual",
      "terraform-version": "1.12.2",
      "updated-at": "2025-07-21T08:42:10.673Z",
      "permissions": {
        "can-apply": true,
        "can-cancel": true,
        "can-comment": true,
        "can-discard": true,
        "can-force-execute": true,
        "can-force-cancel": true,
        "can-override-policy-check": true
      },
      "variables": [],
      "force-cancel-available-at": "2025-07-21T08:43:10.617Z"
    },
    "relationships": {
      "workspace": {
        "data": {
          "id": "ws-***",
          "type": "workspaces"
        }
      },
      "apply": {
        "data": {
          "id": "apply-***",
          "type": "applies"
        },
        "links": {
          "related": "/api/v2/runs/run-***/apply"
        }
      },
      "canceled-by": {
        "data": {
          "id": "user-***",
          "type": "users"
        },
        "links": {
          "related": "/api/v2/runs/run-***/canceled-by"
        }
      },
      "configuration-version": {
        "data": {
          "id": "cv-***",
          "type": "configuration-versions"
        },
        "links": {
          "related": "/api/v2/runs/run-***/configuration-version"
        }
      },
      "created-by": {
        "data": {
          "id": "user-***",
          "type": "users"
        },
        "links": {
          "related": "/api/v2/runs/run-***/created-by"
        }
      },
      "plan": {
        "data": {
          "id": "plan-***",
          "type": "plans"
        },
        "links": {
          "related": "/api/v2/runs/run-***/plan"
        }
      },
      "run-events": {
        "data": [
          {
            "id": "re-***",
            "type": "run-events"
          },
          {
            "id": "re-***",
            "type": "run-events"
          },
          {
            "id": "re-***",
            "type": "run-events"
          }
        ],
        "links": {
          "related": "/api/v2/runs/run-***/run-events"
        }
      },
      "task-stages": {
        "data": [],
        "links": {
          "related": "/api/v2/runs/run-***/task-stages"
        }
      },
      "policy-checks": {
        "data": [],
        "links": {
          "related": "/api/v2/runs/run-***/policy-checks"
        }
      },
      "comments": {
        "data": [],
        "links": {
          "related": "/api/v2/runs/run-***/comments"
        }
      }
    },
    "links": {
      "self": "/api/v2/runs/run-***"
    }
  }
}

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.

$ TFE_ADDRESS="https://example" TFE_TOKEN="example"go test ./... -v -run TestRunsCanceledAt 

=== RUN   TestRunsCanceledAt
=== RUN   TestRunsCanceledAt/when_the_run_is_not_canceled
=== RUN   TestRunsCanceledAt/when_the_run_is_canceled
--- PASS: TestRunsCanceledAt (10.00s)
    --- PASS: TestRunsCanceledAt/when_the_run_is_not_canceled (0.38s)
    --- PASS: TestRunsCanceledAt/when_the_run_is_canceled (0.91s)
PASS
ok      github.com/hashicorp/go-tfe     10.059s

$ TFE_ADDRESS="https://example" TFE_TOKEN="example"go test ./... -v -run TestRunsRunEvents 

go test -run TestRunsRunEvents -v
=== RUN   TestRunsRunEvents
--- PASS: TestRunsRunEvents (4.86s)
PASS
ok      github.com/hashicorp/go-tfe     4.908s

$ TFE_ADDRESS="https://example" TFE_TOKEN="example"go test ./... -v -run TestRunsTriggerReason
=== RUN   TestRunsTriggerReason
--- PASS: TestRunsTriggerReason (5.01s)
PASS
ok      github.com/hashicorp/go-tfe     5.104s

@ctrombley ctrombley self-assigned this Aug 20, 2025
@ctrombley ctrombley requested a review from a team as a code owner August 20, 2025 15:24
@ctrombley ctrombley changed the title Run/fields Add CanceledAt, RunEvents, and TriggerReason to Run Aug 20, 2025
@ctrombley ctrombley merged commit aae07e9 into main Aug 22, 2025
8 checks passed
@ctrombley ctrombley deleted the run/fields branch August 22, 2025 17:42
Copy link

Reminder to the contributor that merged this PR: if your changes have added important functionality or fixed a relevant bug, open a follow-up PR to update CHANGELOG.md with a note on your changes.

mutahhir pushed a commit that referenced this pull request Sep 2, 2025
* Adds CanceledAt, RunEvents, TriggerReason fields to Run

* Updated changelog

---------

Co-authored-by: jpadrianoGo <[email protected]>
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.

3 participants