Search code examples
terraformterraform-provider-awsterraform-cloud

Terraform state file on cloud creating/deleting vm


If I have 15 VMS deployed on the cloud, and I want to create one VM using terraform to test it and I want to delete the one VM. Would my state file include all 16 VMs or just one VM?

What's the best course of action to remove the VM?

  • the state file only has one VM, run terraform destroy
  • delete state file
  • the state file has 16 VMS, run terraform destroy
  • go to cloud console, delete VM and run terraform apply

Solution

  • Assuming that the 15 VMs are already running and not managed by your TF code, then your TF state file would only have one VM (the 16th). Then to delete it, there are two options:

    1. If your TF code does not include anything other resources, run terraform destroy
    2. Delete the VM code from TF file, and run terraform apply