Closed cuntoulishifu closed 1 year ago
Hi @cuntoulishifu thanks for opening the issue! The behavior here is by default in Terraform, that deletion of the dependent resource happens before updating the resource depending on it. According to https://github.com/hashicorp/terraform/blob/main/docs/destroying.md#create-before-destroy, you can reverse this dependency by setting create_before_destroy = true
in the lifecycle
of azurerm_network_interface.default
, then the VM will be updated before deleting the NIC.
Hi @cuntoulishifu thanks for opening the issue! The behavior here is by default in Terraform, that deletion of the dependent resource happens before updating the resource depending on it. According to https://github.com/hashicorp/terraform/blob/main/docs/destroying.md#create-before-destroy, you can reverse this dependency by setting
create_before_destroy = true
in thelifecycle
ofazurerm_network_interface.default
, then the VM will be updated before deleting the NIC.
Hi @myc2h6o thanks a lot your your information! now I know more about Terraform😀! but after adding the create_before_destroy = true
setting I still got the same error message ...😫
@cuntoulishifu I forgot to mention, the create_before_destroy = true
needs to be added before removing the NIC (private_ips
entries). Could you try update the config to add create_before_destroy = true
, trigger a terraform apply
, and then remove the NIC?
I found a similar issue #15483 for reference, which also updates a resource while deleting one of its dependent resource
Thank you for opening this issue. Since the behavior described in your issue is the expected behavior of Terraform. I am going to mark this issue as closed. Hopefully @myc2h6o's suggestions above are able to help you troubleshoot your configuration, if not, please feel free to ask questions in our forum: Azure Provider forum
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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Is there an existing issue for this?
Community Note
Terraform Version
0.13
AzureRM Provider Version
2.89.0
Affected Resource(s)/Data Source(s)
azurerm_network_interface
Terraform Configuration Files
Debug Output/Panic Output
Expected Behaviour
delete azure network interface
Actual Behaviour
Error:
deleting Network Interface: (Name "nic-xxxxxxx-xx.xx.64.102" / Resource Group "xxxx-east2-xxxxxx-rg"):
network.InterfacesClient#Delete: Failure sending request: StatusCode=400 -- Original Error: Code="NicInUse" Message="Network Interface /subscriptions/aaaa-bbbbb-cccc-ddddd-eeeeeeee/resourceGroups/xxxx-east2-xxxx-rg/providers/Microsoft.Network/networkInterfaces/nic-xxxxxwin01-xx.xxx.64.102
is used by existing
resource /subscriptions/aaaa-bbbbb-cccc-ddddd-eeeeeeee/resourceGroups/xxx-xxxx-xxxxxx-RG/providers/Microsoft.Compute/virtualMachines/xxxxtestwin01.
In order to delete the network interface, it must be dissociated from the resource. To learn more, see aka.ms/deletenic." Details=[]
Steps to Reproduce
Important Factoids
Azure China
References
No response