terraform-provider-restapi
terraform-provider-restapi copied to clipboard
Resource destroy fails with custom 'destroy_path' and 'id'
I am working with below resource which gets created without any issues but never gets destroyed. Resource object has custom destroy_path which differs from create_path and non typical ìd (in this example case npool/vms/test-vm-bootvolume) which constructed of ZFS dataset path (npool/vms) and zvol name (test-vm-bootvolume).
resource "restapi_object" "zvol" {
provider = restapi.truenas
path = "/pool/dataset"
data = jsonencode({
name = var.vm_instance.zvol.name
type = "VOLUME"
volsize = 1073741824 # 1GiB
volblocksize = "8K"
})
create_path = "/pool/dataset"
destroy_path = "/pool/dataset/id/{id}"
read_path = "/pool/dataset/id/{id}"
update_path = "/pool/dataset/id/{id}"
}
{id} required to destroy resource is same same as 'name' submitted during create and with terraform show as seen from sniplet below I can confirm that name and id matches after resource is created. I have some doubts if I should use id_attribute and did some experiments with that as well without success.
data = jsonencode(
{
name = "npool/vms/test-vm-bootvolume" <--- THIS
type = "VOLUME"
volblocksize = "8K"
volsize = 1073741824
}
)
destroy_path = "/pool/dataset/id/{id}"
id = "npool/vms/test-vm-bootvolume" <--- THIS
path = "/pool/dataset"
read_path = "/pool/dataset/id/{id}"
update_path = "/pool/dataset/id/{id}"
Any advice how to get destroy resource working?
Hello @kullervo610
As discussed in issue #205 there are no ways (for now) to somehow parse the ID returned form API. Maybe someone will find a workaround for this or it will be fixed on the provider's side
Apologies for the slow reply. I haven't attempted this in a while, but I think you could use native variable interpolation in Terraform for this rather than the provider's interpolation. Something like this?
resource "restapi_object" "zvol" {
provider = restapi.truenas
path = "/pool/dataset"
data = jsonencode({
name = var.vm_instance.zvol.name
type = "VOLUME"
volsize = 1073741824 # 1GiB
volblocksize = "8K"
})
create_path = "/pool/dataset"
destroy_path = "/pool/dataset/id/${var.vm_instance.zvol.name}"
read_path = "/pool/dataset/id/${var.vm_instance.zvol.name}"
update_path = "/pool/dataset/id/${var.vm_instance.zvol.name}"
}
This may just work because you can predict the path based on an input