Terraform: Level 1 - Task 30 - Delete EC2 Instance Using Terraform

As per the task’s description, it asks us to destroy the EC2 instance using Terraform, but leave the provision code for future reference. Therefore, I added count = 0 into the resource block of the instance so that even when new resources are added to the EC2 instance won’t be configured unless the count value is removed. I used the terraform destroy command to destroy the instance. However, the error message shows that I haven’t used “terraform” to destroy the instance. I got the same error when using terraform planterraform apply after adding count = 0 to the resource block. Either way when checking through the AWS CLI the instance was in the “terminated” state. What am I doing wrong?

@Mineth

I’ve checked, and it’s working correctly on my side. For this task, you only need to run terraform destroy without changing any main.tf code. Make sure to wait until the EC2 instance is terminated before submitting the task.

1 Like