Introduction
This article provides a solution for an issue where deleting an organization in Terraform Enterprise fails with a 500 internal server error.
Problem
When you attempt to delete an organization using the Terraform Enterprise UI or API, the action fails and returns a 500 internal server error.
Prerequisites
- Terraform Enterprise version lower than
v202312-1.
Cause
An API request to delete an organization results in an error due to a foreign key constraint violation in the database.
Here is an example of a failing API request.
$ curl \
--header "Authorization: Bearer $TOKEN" \
--header "Content-Type: application/vnd.api+json" \
--request DELETE \
https://<tfe_fqdn>/api/v2/admin/organizations/<organization_name>
## Output
{"errors":[{"status":"500","title":"internal server error"}]}The Terraform Enterprise container logs may show a PG::ForeignKeyViolation error similar to the following output.
{
"component": "atlas",
"log": "... [ERROR] ... PG::ForeignKeyViolation: ERROR: update or delete on table \"users\" violates foreign key constraint \"fk_rails_425d0d7dc7\" on table \"teams\""
}Solution
To resolve this issue, you must upgrade your Terraform Enterprise instance to version v202312-1 or a later release.
Additional Information
- For more details on the API endpoint, refer to the Destroy an Organization API documentation.