Terraform
Destroy a Stack
We recommend destroying a Stack in phases to ensure HCP Terraform destroys your infrastructure safely. Destroy your Stack deployments before destroying the Stack itself to ensure you do not leave any unmanaged infrastructure behind.
Requirements
To destroy a Stack and delete or destroy a deployment in HCP Terraform, you must also be a member of a team with one of the following permissions:
Stack recovery requirements
You can recover a Stack that has been deleted within 30 days from the date and time it was deleted. You must meet the following requirements to recover a Stack:
- Allow deleted workspaces and stacks to be recoverable must be enabled for your organization.
- You must have a paid subscription. Refer to the pricing page for more information.
Delete deployments
Before destroying a Stack, we recommend destroying your deployments to remove the resources that those deployments manage. Otherwise, the infrastructure managed by your Stack’s deployments can continue without destruction, and you will have to clean them up manually.
To destroy a deployment’s infrastructure, add the destroy argument to every deployment block in your deployment configuration file. The following example destroys the production deployment using the destroy argument:
deployments.tfdeploy.hcl
deployment "production" {
inputs = {
region = "us-west-2"
instances = 2
}
destroy = true
}
After uploading the updated deployment configuration file and approving the subsequent plan, HCP Terraform destroys any infrastructure for the production deployment.
After deleting all of a Stack's deployments, you can safely delete that Stack.
Delete a Stack
Before destroying a Stack in HCP Terraform, we strongly recommend deleting all of that Stack’s deployments. Once your Stack contains no deployments, you can delete a Stack by performing the following steps:
Begin by navigating to the Stack you want to interact with:
- Sign in to HCP Terraform, and select the organization that contains your Stack.
- In the navigation menu, click Projects under Manage.
- Select the project containing your Stack.
- Select Settings in the navigation menu.
- Select Destruction and Deletion.
- Click Delete stack <STACK_NAME>.
- Enter
deletein the confirmation modal, then click Delete Stack.
By following the steps above, you can forcefully delete a Stack without removing its deployments first. However, your Stack’s deletion does not affect Stack’s resources, so they continue without management, and you have to clean them up manually.
Recover a Stack
You have 30 days to recover a discarded Stack. During the recovery window, HCP Terraform and Terraform Enterprise continue to record new configuration versions committed through VCS webhooks, but commits don’t trigger new runs. You can’t recover a Stack that has the same name as an existing Stack.
Complete the following steps to recover a discarded workspace:
- Sign in to HCP Terraform or Terraform Enterprise and choose your organization.
- Click Settings in the sidebar, then click Recoverable items.
- For the Stack you want to recover, open the ellipses menu in the Actions column and choose Recover.
- When prompted, click Recover. HCP Terraform recovers the Stack to its last known state before deletion.