Home > Blockchain >  What is the difference between `terraform apply` vs. `terraform destroy` when removing resources?
What is the difference between `terraform apply` vs. `terraform destroy` when removing resources?

Time:09-23

I managed AWS rds instance on Terraform, but the instance is no longer needed so I removed all .tf files for that instance.
In this case, I think I can perform terraform destroy, but do I need to trigger terraform apply before that, or only one of these is enough? I don't fully understand the difference of those two commands when removing resources.

CodePudding user response:

terraform destroy is used to delete/destroy all resources that you managed by your TF files. In contrast, terraform apply is used to apply changes to your TF controlled infrastructure. This means that only selected resources will be changed (or removed), not all.

In your case, since you removed .tf files associated with some instance, terraform apply will just destroy that instance. Other resources will not be affected. However, if you execute terraform destroy everything will be removed, including the instance and anything else that you have created.

  • Related