Unable to remove PVC in Terraform

12/8/2021

I'm trying to implement a PVC in Terraform

resource "kubernetes_persistent_volume_claim" "nfs-claim" {
  metadata {
    name = "nfs-claim"
  }
  spec {
    access_modes = ["ReadWriteMany"]
    resources {
      requests = {
        storage = "500Mi"
      }
    }
  }
}

but upon destroying the infrastructure, Terraform is unable to delete the PVC and keeps trying till it times out, this is due to

finalizers:
  - kubernetes.io/pvc-protection

I could not find in the documentation a way to implement a PVC without finalizers, this terraform is in a pipeline and its main purpose for testing the new modifications to the environment so it has to be deleted. I also tried to manually patch the pvc to remove the finalizer with:

kubectl patch pvc nfs-claim -p '{"metadata":{"finalizers": []}}' --type=merge

but it doesn't work unless the pvc is in terminating state.

Is there a way to implement the PVC without finalizers from the start?

-- Mohammed Hassan
digital-ocean
kubernetes
kubernetes-pvc
persistent-volumes
terraform

0 Answers