Skip to content

Conversation

jpadrianoGo
Copy link
Contributor

@jpadrianoGo jpadrianoGo commented May 19, 2025

Description

This PR adds ConfirmedBy *User relation field to Run struct. Run now includes ConfirmedBy.

The change aims to be part of automating terraform plan/apply verification. This aligns Run.Read return with the API's.

curl
--header "Authorization: Bearer $TOKEN"
--request GET
https://app.terraform.io/api/v2/runs/run-Hukccoek3V9yXb6h

Runs.Read(ctx context.Context, runID string) (*Run, error)

{"data":{"id":"run-","type":"runs","attributes":{"actions":{"is-cancelable":false,"is-confirmable":false,"is-discardable":false,"is-force-cancelable":false},"allow-config-generation":true,"allow-empty-apply":false,"auto-apply":false,"canceled-at":null,"created-at":"2025-04-29T06:05:13.747Z","has-changes":true,"is-destroy":false,"message":"Triggered via UI","plan-only":false,"refresh":true,"refresh-only":false,"replace-addrs":[],"save-plan":false,"source":"tfe-ui","status-timestamps":{"applied-at":"2025-04-29T06:26:05+00:00","planned-at":"2025-04-29T06:11:59+00:00","queuing-at":"2025-04-29T06:11:15+00:00","applying-at":"2025-04-29T06:25:43+00:00","planning-at":"2025-04-29T06:11:33+00:00","confirmed-at":"2025-04-29T06:25:27+00:00","plan-queued-at":"2025-04-29T06:11:16+00:00","apply-queued-at":"2025-04-29T06:25:27+00:00","queuing-apply-at":"2025-04-29T06:25:27+00:00","cost-estimated-at":"2025-04-29T06:12:00+00:00","plan-queueable-at":"2025-04-29T06:11:15+00:00","policy-checked-at":"2025-04-29T06:12:06+00:00","cost-estimating-at":"2025-04-29T06:11:59+00:00"},"status":"applied","target-addrs":null,"trigger-reason":"manual","terraform-version":"..","updated-at":"2025-04-29T06:26:05.994Z","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":[]},"relationships":{"workspace":{"data":{"id":"ws-","type":"workspaces"}},"apply":{"data":{"id":"apply-","type":"applies"},"links":{"related":"/api/v2/runs/run-/apply"}},"configuration-version":{"data":{"id":"cv-","type":"configuration-versions"},"links":{"related":"/api/v2/runs/run-/configuration-version"}},"confirmed-by":{"data":{"id":"user-","type":"users"},"links":{"related":"/api/v2/runs/run-/confirmed-by"}},"cost-estimate":{"data":{"id":"ce-","type":"cost-estimates"},"links":{"related":"/api/v2/cost-estimates/ce-"}},"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"}],"links":{"related":"/api/v2/runs/run-/run-events"}},"task-stages":{"data":[],"links":{"related":"/api/v2/runs/run-/task-stages"}},"policy-checks":{"data":[{"id":"polchk-","type":"policy-checks"}],"links":{"related":"/api/v2/runs/run-/policy-checks"}},"comments":{"data":[],"links":{"related":"/api/v2/runs/run-/comments"}}},"links":{"self":"/api/v2/runs/run-"}}}

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 TestRunsConfirmedBy. The new tests should pass.
  3. ConfirmedBy is read for 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 TestRunsConfirmedBy

go test -run TestRunsConfirmedBy -v ./... -count=1 -timeout=0
 === RUN TestRunsConfirmedBy
 === RUN TestRunsConfirmedBy/with_apply
     helper_test.go:1267: Polling run "run-Hukccoek3V9yXb6h" for status included in ["planned" "errored"] with deadline of 2025-05-19 12:29:18.9216227 +0800 PST m=+123.214070107
     helper_test.go:1273: ...
     helper_test.go:1331: Reading run "run-Hukccoek3V9yXb6h"
     helper_test.go:1279: Run "run-Hukccoek3V9yXb6h" had status "plan_queued"
     helper_test.go:1273: ...
     helper_test.go:1331: Reading run "run-Hukccoek3V9yXb6h"
     helper_test.go:1279: Run "run-Hukccoek3V9yXb6h" had status "planning"
     helper_test.go:1273: ...
     helper_test.go:1331: Reading run "run-Hukccoek3V9yXb6h"
     helper_test.go:1279: Run "run-Hukccoek3V9yXb6h" had status "planned"
     helper_test.go:1343: Applying run "run-Hukccoek3V9yXb6h"
     helper_test.go:1267: Polling run "run-Hukccoek3V9yXb6h" for status included in ["applied" "errored"] with deadline of 2025-05-19 12:29:27.390930802 +0800 PST m=+131.683378232
     helper_test.go:1273: ...
     helper_test.go:1331: Reading run "run-Hukccoek3V9yXb6h"
     helper_test.go:1279: Run "run-Hukccoek3V9yXb6h" had status "apply_queued"
     helper_test.go:1273: ...
     helper_test.go:1331: Reading run "run-Hukccoek3V9yXb6h"
     helper_test.go:1279: Run "run-Hukccoek3V9yXb6h" had status "applying"
     helper_test.go:1273: ...
     helper_test.go:1331: Reading run "run-Hukccoek3V9yXb6h"
     helper_test.go:1279: Run "run-Hukccoek3V9yXb6h" had status "applied"
 === RUN TestRunsConfirmedBy/without_apply
     helper_test.go:1267: Polling run "run-RZoBTvF9PfpWdBjz" for status included in ["cost_estimated" "planned" "errored"] with deadline of 2025-05-19 12:32:43.041909365 +0800 PST m=+327.334356774
     helper_test.go:1273: ...
     helper_test.go:1331: Reading run "run-RZoBTvF9PfpWdBjz"
     helper_test.go:1279: Run "run-RZoBTvF9PfpWdBjz" had status "plan_queued"
     helper_test.go:1273: ...
     helper_test.go:1331: Reading run "run-RZoBTvF9PfpWdBjz"
     helper_test.go:1279: Run "run-RZoBTvF9PfpWdBjz" had status "planning"
     helper_test.go:1273: ...
     helper_test.go:1331: Reading run "run-RZoBTvF9PfpWdBjz"
     helper_test.go:1279: Run "run-RZoBTvF9PfpWdBjz" had status "planned"
 --- PASS: TestRunsConfirmedBy (40.42s)
     --- PASS: TestRunsConfirmedBy/with_apply (22.56s)
     --- PASS: TestRunsConfirmedBy/without_apply (16.84s)
 PASS
 ok [github.com/hashicorp/go-tfe](http://github.com/hashicorp/go-tfe) 40.422

@jpadrianoGo jpadrianoGo requested a review from a team as a code owner May 19, 2025 08:58
@jpadrianoGo jpadrianoGo changed the title Added ConfirmedBy to Run struct as a valid relation Added ConfirmedBy field to Run struct May 20, 2025
@jpadrianoGo jpadrianoGo changed the title Added ConfirmedBy field to Run struct Add ConfirmedBy field to Run struct May 20, 2025
@jpadrianoGo jpadrianoGo changed the title Add ConfirmedBy field to Run struct Add ConfirmedBy field to Run May 20, 2025
@jpadrianoGo jpadrianoGo changed the title Add ConfirmedBy field to Run Add ConfirmedBy to Run May 20, 2025
Copy link
Collaborator

@ctrombley ctrombley left a comment

Choose a reason for hiding this comment

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

LGTM

@jpadrianoGo
Copy link
Contributor Author

Thank you @ctrombley for the feedback.

@ctrombley
Copy link
Collaborator

Superseded by #1113.

@ctrombley ctrombley closed this May 21, 2025
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