0
0
Terraformcloud~30 mins

Terraform destroy for cleanup - Mini Project: Build & Apply

Choose your learning style9 modes available
Terraform destroy for cleanup
📖 Scenario: You have created a simple cloud infrastructure using Terraform. Now, you want to learn how to clean up and remove all the resources you created to avoid extra costs.
🎯 Goal: Learn how to write a Terraform configuration for a basic resource and then use terraform destroy to clean up the resources safely.
📋 What You'll Learn
Create a Terraform configuration file with a simple resource
Initialize Terraform in the project directory
Apply the Terraform configuration to create the resource
Use terraform destroy to remove the resource
💡 Why This Matters
🌍 Real World
Cloud engineers often create resources for testing or development. Cleaning up with <code>terraform destroy</code> helps avoid unnecessary costs and keeps the cloud environment tidy.
💼 Career
Knowing how to safely create and destroy infrastructure with Terraform is essential for cloud infrastructure management roles.
Progress0 / 4 steps
1
Create a Terraform configuration with an AWS S3 bucket
Create a file named main.tf and write a Terraform configuration that defines an AWS S3 bucket resource named my_bucket with the bucket name my-unique-bucket-12345. Use the AWS provider with region us-east-1.
Terraform
Need a hint?

Start by declaring the AWS provider with the region us-east-1. Then define an S3 bucket resource with the exact name my_bucket and bucket name my-unique-bucket-12345.

2
Initialize Terraform in the project directory
Write the Terraform CLI command to initialize the Terraform working directory so that the AWS provider plugin is downloaded and ready.
Terraform
Need a hint?

Use the command terraform init to prepare your working directory.

3
Apply the Terraform configuration to create the S3 bucket
Write the Terraform CLI command to apply the configuration and create the S3 bucket resource. Use the -auto-approve flag to skip manual approval.
Terraform
Need a hint?

Use terraform apply -auto-approve to create the resources without manual confirmation.

4
Destroy the Terraform-managed infrastructure to clean up
Write the Terraform CLI command to destroy all the resources created by Terraform. Use the -auto-approve flag to skip manual approval.
Terraform
Need a hint?

Use terraform destroy -auto-approve to remove all resources without manual confirmation.