How to delete a unattached persistent disk

Hi All,

trying to understand how can i delete an unattached persistent disk in GCP through terraform.

the disk was set to auto_delete = false while creating the VM, however we do not need this disk anymore, VM is destroyed however the disk still remains undeleted for obvious reason.

could someone help me understand how can we delete this disk now.

Hi @goutam04 ,
was the VM and and disk deployed using terraform or without?
Was the VM deleted using terraform or e.g. CLI?

Most probably the disk isn’t tracked within the terraform state. In that case the disk has to be imported into state and could then get removed.

Hi @tbugfinder thanks for your respose … its managed through terraform.

while building the infrastructure i set below -

disk {
source_image= “debian-cloud/debian-9”
auto_delete = false
device_name = “boot-disk”
}

now i have deleted the VM but since the disk was set to no autodelete, its still there and i am trying to find a way to delete it through terraform. there is no VM anymore its just the disk.

Ok, in that case the disk isn’t managed by terraform any longer, it isn’t within terraform state.

You can try to import the disk into terraform state and then drop it during the apply phase.

https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_disk#import

@tbugfinder thanks a lot really appreciate your assistance and help