Terraform
Destroy resources and workspaces
In the previous tutorials, you created an EC2 instance in AWS and an HCP Terraform workspace and project.
In this tutorial, you will destroy the EC2 instance and delete your HCP Terraform workspace and project.
Tip
If you want to explore more HCP Terraform tutorials, destroy your infrastructure but do not delete the project in this tutorial.
Destroy infrastructure
There are two ways to destroy infrastructure with Terraform:
- If you want to remove individual resources, you can remove the infrastructure from your configuration and perform an apply operation.
- If you want to remove every resource in your workspace, you can run a destroy operation.
HCP Terraform allows you to destroy infrastructure as a part of the standard workflow.
To destroy the infrastructure you provisioned in these tutorials, navigate to your learn-hcp-terraform-run-triggers
workspace overview page. Click Settings, then click Destruction and Deletion.
This page offers two operations:
- Queue destroy plan destroys all infrastructure managed by the workspace.
- Delete from HCP Terraform deletes your workspace from HCP Terraform without destroying the infrastructure the workspace manages.
Warning
Deleting a workspace does not destroy its infrastructure. The AWS EC2 instance you provisioned will continue to exist after deleting this workspace.
Click the Queue destroy plan button.
HCP Terraform requires you to enter your workspace name before you can queue a destroy plan. When prompted, enter your workspace name and queue the plan.
HCP Terraform creates a plan to destroy every resource in your workspace. In this case, HCP Terraform reports that it plans to delete your EC2 instance.
Click Confirm & apply, then click Confirm plan to apply the destroy plan.
Repeat these steps for your learn-hcp-terraform
workspace.
Delete workspace
When you run a destroy operation in HCP Terraform, it deletes all resources the workspace manages, but it does not delete the workspace. This is useful if you want to deploy these resources again at a later time. Your configuration and workspace variables still exist in HCP Terraform.
If you want to delete your configuration and workspace variables from HCP Terraform, you can choose to delete the workspace as well. To delete the workspace, click Settings, then click Destruction and Deletion. Under the Delete Workspace section, click Delete from HCP Terraform.
HCP Terraform prompts you to confirm that you want to delete the workspace. Follow the instruction in the prompt, then click Delete.
Delete project and variable set
Tip
Don't destroy your project, yet, if want to continue using our tutorials to learn Terraform or want to create more workspaces that can use your AWS credentials. Since this project contains a variable set to authenticate against AWS, you can create additional workspaces in this project that inherit these variables.
Now that your project is empty and no workspaces use your variable set, you can delete the project and set of variables. Because your variable set is scoped to your project, deleting the project also deletes the variables.
From your organization's overview page, click Projects then choose your Learn Terraform
project. Click Settings* in the left navigation panel, then under Delete project click Delete. HCP Terraform prompts you to confirm that you want to delete the project. Enter your project name and click Delete** to confirm.
Next steps
In this tutorial, you deleted the resources that you deployed in previous tutorials, then deleted your workspace, project, and variable set in HCP Terraform.
Learn more about the concepts you used in these tutorials by exploring the following documentation:
- Refer to the workspaces documentation to learn more about how to configure how HCP Terraform manages your configuration, state, and Terraform operations.
- Read the projects documentation to learn more about how to organize your workspaces and scope access to workspace resources.
- Read the remote operations documentation to learn how HCP Terraform performs different types of Terraform operations.
To explore more of HCP Terraform's features, continue to the following documentation and tutorials:
- Learn how to use the CLI-driven remote run workflow to perform Terraform operations remotely from your local machine.
- Migrate state to HCP Terraform to start managing your existing Terraform state with HCP Terraform.
- Enforce policy with Sentinel to enforce your organization's best practices.
- Share modules in the private registry to reuse common configuration with others on your team.
- Learn how HCP Terraform run tasks let you integrate third-party tools and services into your Terraform operations.