ionos-cloud/terraform-provider-ionoscloud

Can't delete LAN if it is connected to a nodepool

simoncolincap opened this issue · 7 comments

Description

Terraform can't delete a LAN if it is connected to a nodepool because it tries to delete the LAN before disconnecting it from the nodepool. Terraform tries to delete the LAN for an hour and then fails with the error: "Error: nics deletion check timed out! WARNING: your lan nics may still be deleted; check your Ionos Cloud account for updates and perform again a destroy for remaining resources". This can also prevent other resources from being created.

Expected behavior

Terraform disconnects the LAN from the nodepool and then deletes it.

Environment

Terraform version:

Terraform v1.1.4

Provider version:

registry.terraform.io/ionos-cloud/ionoscloud v6.1.3

OS:

Ubuntu 20.04.4 LTS

How to Reproduce

  1. Run this Terraform code
resource "ionoscloud_datacenter" "example" {
  name        = "datacenter name"
  location    = "de/txl"
}

resource "ionoscloud_lan" "example" {
  datacenter_id = ionoscloud_datacenter.example.id
  public        = false
}

resource "ionoscloud_k8s_cluster" "example" {
  name        = "example"
}

resource "ionoscloud_k8s_node_pool" "demo" {
  name        = "demo"
  k8s_version = "1.22.12"
  lans {
    id   = ionoscloud_lan.example.id
    dhcp = true
  }
  datacenter_id     = ionoscloud_datacenter.example.id
  k8s_cluster_id    = ionoscloud_k8s_cluster.example.id
  cpu_family        = "INTEL_SKYLAKE"
  availability_zone = "AUTO"
  storage_type      = "HDD"
  node_count        = 1
  cores_count       = 2
  ram_size          = 2048
  storage_size      = 40
}
  1. Delete ionoscloud_lan.example and remove the lans block from ionoscloud_k8s_node_pool.demo
  2. Run terraform apply

Thanks for creating this!

There's a cycle in the backend that prevents the deletion of the lan before it is removed from the nodepool. Could you check if setting create_before_destroy to true helps in fixing this:

 resource "ionoscloud_lan" "example" {
   datacenter_id = ionoscloud_datacenter.example.id
   public        = false
    lifecycle {
    create_before_destroy = true
    }
 }

I tried setting create_before_destroy on the LAN but it didn't change the behavior.

If you do a terraform apply with the create_before_destroy and then try to remove the lan resource and the lans field in the nodepool and run terraform apply again, does it still try to destroy the lan first? Or does it try to update the nodepool first? Thanks!

If create_before_destroy doesn't work, the only workaround is to first remove the
lans { id = ionoscloud_lan.example.id dhcp = true } in the ionoscloud_k8s_node_pool run apply and only after remove the ionoscloud_lan resource and run apply again.

Sorry I didn't get around to replying earlier. Setting create_before_destroy works but I had to run one Terraform apply before deleting the LAN even if the Terraform apply didn't actually show any changes. When we encountered the issue we just disconnected the LAN in the DCD and then ran Terraform to delete it. Ideally I think the create_before_destroy behavior should be the default to avoid the long Terraform run time and confusing error message.

We will add it in the documentation with a note. Thanks!