Problem
Unable to delete an organization in Terraform Enterprise
Prerequisites
- Terraform Enterprise version lower then v202312-1
Cause
Attempting to delete an organization using UI or API results in an internal 500 error
API example:
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"}]
In the container logs you might see an issue like the following
2023-10-24T11:33:12.795785000Z {"component":"atlas","log":"2023-10-24 11:33:11
[ERROR] [5e2820cd-fe07-4208-a50c-b674e020341b]
[dd.service=atlas dd.trace_id=494634590008281533 dd.span_id=0 ddsource=ruby]
error=ActiveRecord::InvalidForeignKey id=121790580
message=PG::ForeignKeyViolation:
ERROR: update or delete on table \"users\" violates foreign key constraint \"fk_rails_425d0d7dc7\" on table \"teams\""}
Solution
Upgrade Terraform Enterprise to release v202312-1
Additional Information
-
API documentation for deleting an organization can be found here