Terraform Destroy

In this tutorial, you will destroy the EC2 instance and delete your Terraform Cloud workspace.

Over the course of these tutorials, you created an EC2 instance in AWS, a Terraform Cloud workspace, and a GitHub repository.

Destroy infrastructure

Now that you have provisioned and changed infrastructure with Terraform Cloud, the final stage of your infrastructure’s lifecycle is to destroy it. Terraform Cloud allows you to destroy the infrastructure you have provisioned as a part of the standard workflow.

To destroy the infrastructure you provisioned in these tutorials, go to your workspace in the Terraform Cloud UI. Next, from the top menu, select “Settings -> Destruction and Deletion”.

Terraform Cloud workspace destruction and deletion

From this page you can:

  • Queue destroy plan destroys all infrastructure managed by the workspace.
  • Delete from Terraform Cloud deletes your workspace from Terraform Cloud without destroying the infrastructure the workspace manages.

Deleting a workspace does not destroy its infrastructure. For example, if you were to delete this workspace, the AWS EC2 instance you provisioned earlier would still exist.

Queue a destroy plan

Click the red “Queue destroy plan” button.

Terraform Cloud will prompt you to enter your workspace name before you can queue a destroy plan.

Queue Destroy Plan

Enter your workspace name and queue the plan.

Destroy the infrastructure

As it does with all plans, Terraform Cloud will ask you to “Confirm and Apply” the plan. Do so now to destroy your EC2 instance.

After a few minutes, the apply step should complete successfully.

Terraform Cloud workspace destroy infrastructure run

Verify that Terraform destroyed the EC2 instance by visiting the AWS web console in the region where you created it. The configuration defaults to region N. California/us-west-1.

Delete the AWS IAM user (optional)

If you created an AWS IAM user for these tutorials, delete or disable this user in the AWS console. Navigate to the Identity Access Management (IAM) section, and then to the user you created. Use the AWS Console to delete the user, or disable the user’s access keys.

Delete the workspace (optional)

If you plan to continue to the next tutorial in this collection and your organization does not contain other workspaces, do not destroy the workspace created.

If you do not plan to run these tutorials again and want to keep your Terraform Cloud organization clean, you can delete the workspace you created. Terraform Cloud does not limit the number of workspaces you have or charge per workspace, so whether you delete the workspace is up to you.

To delete the workspace, return to the “Settings -> Destruction & Deletion” page, and click the red “Delete from Terraform Cloud” button.

Terraform Cloud will prompt you to enter your workspace name before you can click “Delete workspace”. Input the workspace name and click the button to delete the workspace.

Delete workspace

Next steps

In these tutorials you used Terraform Cloud to provision, change, and destroy infrastructure. Now you are ready to learn more about developing Terraform configurations. We recommend downloading the Terraform CLI so you can develop configurations locally. Get started with the CLI on your preferred cloud platform:

At the end of the CLI tutorials you will log into Terraform Cloud via the CLI, and get practice with Terraform Cloud’s CLI-driven workflow.

You can use the CLI workflow alongside the VCS workflow in these tutorials to develop infrastructure configuration locally, commit it to version control, and deploy it into production.

To explore Terraform Cloud’s paid features (which you can enable with a free trial), continue to the next tutorial. These include enforcing policies with Sentinel policy-as-code, and estimating the cost of infrastructure changes.

Learn more about the concepts you used in these tutorials by exploring the documentation.