Terraform-provider-azurerm: cannot destroy azurerm_network_interface_backend_address_pool_association when the network interface was manually deleted

Created on 11 Dec 2018  ·  7Comments  ·  Source: terraform-providers/terraform-provider-azurerm

I was trying to launch two virtual machines behind a load balancer. But after 45 minutes, azure failed to create one of the machines, to try to recover the situation, I've manually deleted the virtual machine and tried to run terraform apply again, but it kept on failing due to missing resources, until I've end-up with:

Error: Error refreshing state: 1 error(s) occurred:

* azurerm_network_interface_backend_address_pool_association.web: 2 error(s) occurred:

* azurerm_network_interface_backend_address_pool_association.web[1]: azurerm_network_interface_backend_address_pool_association.web.1: Network Interface "web2" (Resource Group "rgl-load-balancer-example") was not found!
* azurerm_network_interface_backend_address_pool_association.web[0]: azurerm_network_interface_backend_address_pool_association.web.0: Network Interface "web1" (Resource Group "rgl-load-balancer-example") was not found!

Which I could not recover from. This made me think that terraform should not refuse to run when a resource was manually delete from azure portal. It should ignore that fact and assume the resource was MIA and re-create it again.

Terraform (and AzureRM Provider) Version

Terraform v0.11.9

  • provider.azurerm v1.19.0
  • provider.random v2.0.0

Affected Resource(s)

  • azurerm_network_interface_backend_address_pool_association

Configuration

resource "azurerm_lb_backend_address_pool" "web" {
  resource_group_name = "${azurerm_resource_group.example.name}"
  loadbalancer_id     = "${azurerm_lb.web.id}"
  name                = "web"
}

resource "azurerm_network_interface_backend_address_pool_association" "web" {
  count                   = "${var.web_vm_count}"
  network_interface_id    = "${azurerm_network_interface.web.*.id[count.index]}"
  ip_configuration_name   = "web"
  backend_address_pool_id = "${azurerm_lb_backend_address_pool.web.id}"
}

Expected Behavior

It should ignore manually deleted / non-long existing resources.

Actual Behavior

It refuses to do anything.

Steps to Reproduce

  1. terraform apply
  2. manually delete a network interface that is also inside the load balancer backend
  3. try terraform apply or destroy
bug servicnetwork-interfaces

Most helpful comment

This is still an unsolved problem.
If a VM NIC that is in a load balancer is removed from outside TF, on a plan, apply, or refresh TF just bails. I would expect it to recreate the resource. Not pack a sad.

All 7 comments

Additional information for this since we have experience this issue as well. This worked in the 1.19 release and was broken in 1.20. We have logs verifying such.

Correction, this correctly worked with removed associations but fails when the nic has been deleted.

How did you recover from this state?

Having the same issue.
After removing various items from the state, I finally got it to run after running:
terrafrom state rm azurerm_network_interface_backend_address_pool_association.nameoftheassociation
for the association that had the NIC in it.

Don't know if it would have worked if that had been the first thing I deleted or it was cumulative.

This issue is a subset of issue #4330

This is still an unsolved problem.
If a VM NIC that is in a load balancer is removed from outside TF, on a plan, apply, or refresh TF just bails. I would expect it to recreate the resource. Not pack a sad.

This has been released in version 2.26.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "azurerm" {
    version = "~> 2.26.0"
}
# ... other configuration ...

I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

Was this page helpful?
0 / 5 - 0 ratings