Problem
Unable to delete organization in HCP Terraform.
Deleting organization gives 504 Gateway Time-out and attempting to delete any workspaces within also produces this error "Cannot read properties of null (reading ‘attr’”)
Cause
-
Deleting an organization using UI or API results in an internal 504 error -
UI Error :
API Error :
Error deleting organization
<html> <head><title>504 Gateway Time-out</title></head> <body> <center><h1>504 Gateway Time-out</h1></center> </body> </html>
This can be due to following reasons -
-
- Multiple unfinished or pending runs across different workspaces that needs attention
- Any workspace which is preventing your organization to be deleted
- Some backend issue due to which org deletion is not permitted
Solutions:
- Please ensure all the unfinished runs are canceled or completed. You can manage all the runs in your workspaces by navigating to Organization > Settings > Runs
If the issue still persists, please try deleting all the workspaces to see if there is any particular workspace which is preventing your organization to be deleted.
- In order to bulk delete the workspaces in your terraform organisation using API calls, follow the below commands :
Get a list of workspace ID's:
curl \
--header "Authorization: Bearer $TOKEN" \
--header "Content-Type: application/vnd.api+json" \
https://app.terraform.io/api/v2/organizations/:organization_name/workspaces | jq '.data[].id'
Delete each workspace by workspace ID:
- Safe delete:
curl \
--header "Authorization: Bearer $TOKEN" \
--header "Content-Type: application/vnd.api+json" \
--request POST \
https://app.terraform.io/api/v2/workspaces/:worspace_id/actions/safe-delete
- Force delete:
curl \
--header "Authorization: Bearer $TOKEN" \
--header "Content-Type: application/vnd.api+json" \
--request DELETE \
https://app.terraform.io/api/v2/workspaces/:worspace_id
When all the workspaces are deleted, run this API to destroy the organization:
curl \
--header "Authorization: Bearer $TOKEN" \
--header "Content-Type: application/vnd.api+json" \
--request DELETE \
https://app.terraform.io/api/v2/organizations/:organization_name
-
If you are still not able to solve your issue, please reach out HCP Terraform support at
tf-cloud@hashicorp.support or submit a ticket via our support portal.
Additional Information
-
API documentation for deleting an organization can be found here