Introduction
This article provides a procedure to list all service accounts in a Terraform Enterprise organization using the Admin API. Service accounts are created automatically by Terraform Enterprise for internal operations and are not managed by administrators.
Procedure
Complete the following steps to generate a list of all service accounts.
-
Set an environment variable for your user API token. This token must have permissions to access the Admin API.
$ export TOKEN="<YOUR_USER_API_TOKEN>"
-
Use the Admin API to list all users and redirect the output to a file named
input.json. Replace<TFE_HOSTNAME>with your Terraform Enterprise hostname.$ curl \ --header "Authorization: Bearer $TOKEN" \ --header "Content-Type: application/vnd.api+json" \ "https://<TFE_HOSTNAME>/api/v2/admin/users" | jq > input.json
-
Filter the results from
input.jsonto select only the service accounts and save the output to a file namedresult.json.$ jq '.data[] | select(.attributes["is-service-account"] == true)' input.json > result.json
The
result.jsonfile now contains a list of all service accounts in your Terraform Enterprise organization.
Additional Information
For more details, refer to the List all users API documentation.