Thursday, February 14, 2019

Terraform destroy single resource or all resources | How to destroy a specific resource using Terraform in AWS cloud

If you would like to destroy all the resources you had created using Terraform, all you have to do is perform the below command:
 
terraform destroy
and type yes to confirm to delete all the resources.

The above command will destroy all the resources.
 
But let's say you would like to destroy only a specific resource you have created using Terraform. You can do it by passing an argument in terraform destroy command. For e.g., if you would like to delete an EC2 instance, you can mention like below:

Destroy specific resource:

First get all the resources created by Terraform:
terraform state list

f you would like to delete the EC2 instance,
terraform destroy -target aws_instance.myInstanceName

if you would like to delete a security group, you can mention like below:
terraform destroy -target aws_security_group.security_group_name
 
Please watch in my YouTube channel on how to do the above steps:


No comments:

Post a Comment

How to create Ubuntu 22.0.4 Virtual Machine (VM) in Azure? | Create Ubuntu 22.0.4 VM in Azure | How to connect to Azure VM from your local machine

 How to Create Ubuntu 22.0.4 Virtual Machines(VM) in Azure portal? Creating Virtual Machine is easy and straight forward in Azure Cloud. Let...