Problem
When attempting to add a user to a team in Terraform Enterprise using the official API endpoint, the following error is encountered:
Cause
The API documentation includes the following key path information for the request payload:
Key path | Type | Default | Description |
---|---|---|---|
data[].type | string | Must be "users"
|
|
data[].id | string | The ID of the user you want to add to this team |
While the description states that the id
should be the ID of the user, in practice, the API expects the username (e.g., john
) instead of the user's system-generated ID. Using the user ID results in a 400 Bad Request
error with the message "user-xyz does not exist"
.
Pre-requisites -:
-
You have admin or team management access in Terraform Enterprise.
-
You have the correct team ID to which the user should be added.
-
The user already exists in the Terraform Enterprise organization.
-
API authentication token with sufficient permissions is configured.
Solutions:
To resolve this issue, use the username instead of the user ID in the id
field of the payload. The correct request payload should look like:
cat payload.json
{
"data": [
{
"type": "users",
"id": "john"
}
]
}
This format successfully adds the user to the team, as expected.
Outcome
After updating the payload.json to use the username instead of the user ID, the API request should succeed, and the user will be added to the team without error.