0
0
Terraformcloud~10 mins

Terraform destroy for cleanup - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Terraform destroy for cleanup
Start: Terraform destroy command
Load current state file
Plan resource destruction
Show resources to be destroyed
User confirms destruction
Yes
Destroy resources in cloud
Update state file to remove destroyed resources
End
Terraform destroy loads the current state, plans resource removal, asks for confirmation, then deletes resources and updates the state.
Execution Sample
Terraform
terraform destroy
# Confirm with 'yes' when prompted
# Resources get deleted
# State file updates
This command deletes all resources tracked by Terraform and cleans up the state.
Process Table
StepActionEvaluationResult
1Run 'terraform destroy'Command startsTerraform loads state file
2Plan destructionIdentify all resourcesList resources to delete
3Prompt userWait for confirmationUser inputs 'yes'
4Destroy resourcesSend delete requestsResources deleted in cloud
5Update stateRemove destroyed resourcesState file updated
6FinishAll resources removedCleanup complete
💡 All resources destroyed and state file cleaned up, process ends.
Status Tracker
VariableStartAfter Step 2After Step 4Final
state_fileContains all resourcesMarked for deletionEmpty or updatedCleaned state
Key Moments - 3 Insights
Why does Terraform ask for confirmation before destroying?
Terraform shows planned deletions (see step 3 in execution_table) to prevent accidental loss of resources.
What happens if you say 'no' at the confirmation prompt?
Terraform stops the destroy process at step 3, so no resources are deleted and state remains unchanged.
Does Terraform delete resources immediately after running the command?
No, it first plans and waits for confirmation (steps 2 and 3), then deletes resources (step 4).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what happens at step 4?
ATerraform updates the state file
BTerraform sends delete requests to cloud resources
CTerraform waits for user confirmation
DTerraform loads the state file
💡 Hint
Check the 'Action' and 'Result' columns at step 4 in execution_table.
At which step does Terraform ask for user confirmation?
AStep 5
BStep 2
CStep 3
DStep 1
💡 Hint
Look for 'Prompt user' action in execution_table.
If the user inputs 'no' at confirmation, what changes in variable_tracker?
Astate_file remains unchanged
Bstate_file is updated to remove resources
Cstate_file is deleted
Dstate_file is corrupted
💡 Hint
Refer to key_moments about confirmation and step 3 in execution_table.
Concept Snapshot
terraform destroy
- Loads current state
- Plans resource deletion
- Asks for user confirmation
- Deletes resources if confirmed
- Updates state file
Use to clean up all managed infrastructure safely.
Full Transcript
Terraform destroy is a command to remove all resources managed by Terraform. When you run it, Terraform first loads the current state file to know what resources exist. Then it plans which resources will be deleted and shows this list to you. It asks for your confirmation before proceeding. If you type 'yes', Terraform sends delete requests to the cloud provider to remove the resources. After deletion, it updates the state file to reflect that these resources no longer exist. If you say 'no', Terraform stops and does not delete anything. This process helps you clean up your infrastructure safely and avoid accidental deletions.