Introduction
This article outlines the procedure to retrieve detailed user information associated with Terraform Enterprise runs. Specifically, we demonstrate how to extract the user_id
of the individual who triggered a specific run and subsequently fetch their username using API calls. This information can be useful for auditing, troubleshooting, and monitoring purposes.
Expected Outcome
By completing the above steps, you can achieve the following outcomes:
-
Retrieve the
user_id
of the individual who triggered the specified Terraform run. -
Use the
user_id
to fetch additional detail such as the username .
Use Case
In scenarios where you need to identify the user who initiated a Terraform run, this method provides a systematic approach. Whether you are tracking activity for compliance or debugging issues, having access to the triggering user's details can streamline your efforts.
Procedure
Step 1: Retrieve the user_id of the User Who Created the Run
To identify the user associated with a specific Terraform run, use the following API call:
curl \
--header "Authorization: Bearer $TOKEN" \
https://app.terraform.io/api/v2/runs/run-EXA5Ldb78CDjaDQS/run-events | jq .
Explanation:
-
Replace
run-EXA5Ldb78CDjaDQS
with the actual run ID. -
$TOKEN
should be your Terraform Enterprise API token with the necessary permissions. -
The
jq .
at the end of the command formats the output for better readability.
The output of this command will include the user_id
of the user who created the run.
Step 2: Retrieve the Username Using the user_id
Once you have the user_id
, you can retrieve the username of the associated user by executing the following API call:
curl \
--header "Authorization: Bearer $TOKEN" \
--header "Content-Type: application/vnd.api+json" \
--request GET \
https://app.terraform.io/api/v2/users/user-xrY39z2oJaVPQJXd | jq .
Explanation:
-
Replace
user-xrY39z2oJaVPQJXd
with theuser_id
obtained in the previous step. -
$TOKEN
should be your Terraform Enterprise API token. -
jq .
formats the output for better readability.
The API response will contain detailed information about the user, including their username.