3. Delete Resources

  • If we want to destroy the instance that we created, we can use the command terraform destroy

  • Keep in mind that by default it destroys all the resources specified in the config file

  • To delete a single resource, specific flags must be passed to the command

  • In the previous example, if we want to delete the ec2 instance without using terraform destroy command, then, we will comment out the ec2 resource and re apply the config. Terraform will figure it out and delete the ec2 instance for us

#####################
# Modifying EC2 Instance Tag
#####################
#resource "aws_instance" "my-first-server" {
#    ami = "ami-052efd3df9dad4825"
#    instance_type = "t2.micro"
#
#    tags = {
#        Name = "ubuntu"
#    }
#}

Last updated