I'm facing this issue that seems is a bug, asked the question in slack pulumi-azure channel, was advised to create a ticket here.
This is pulumi-python to create VM and network interface, then change custom_data of the VM which result in replacement of the resource. Pulumi up returned the following error:
azure:compute:LinuxVirtualMachine (WebVM):
error: creating Linux Virtual Machine "xxxx" (Resource Group "xxxx"): compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code="NicInUse" Message="Network Interface networkinterface1 is used by existing resource /subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Compute/virtualMachines/xxxx. In order to delete the network interface, it must be dissociated from the resource.
As both the VM and the NIC are created thru the same pulumi script, I expected pulumi to handle the dependency gracefully to first delete the old VM which would dissociate the NIC and then create the new VM which is to link with the NIC. However, it looks like pulumi tried to create the new VM before deleting the old VM, hence resulted the error above.
Hi there,
I'm facing this issue that seems is a bug, asked the question in slack pulumi-azure channel, was advised to create a ticket here.
This is pulumi-python to create VM and network interface, then change custom_data of the VM which result in replacement of the resource. Pulumi up returned the following error: azure:compute:LinuxVirtualMachine (WebVM): error: creating Linux Virtual Machine "xxxx" (Resource Group "xxxx"): compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code="NicInUse" Message="Network Interface networkinterface1 is used by existing resource /subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Compute/virtualMachines/xxxx. In order to delete the network interface, it must be dissociated from the resource.
As both the VM and the NIC are created thru the same pulumi script, I expected pulumi to handle the dependency gracefully to first delete the old VM which would dissociate the NIC and then create the new VM which is to link with the NIC. However, it looks like pulumi tried to create the new VM before deleting the old VM, hence resulted the error above.
Code snippet as following:
network_interface = azure.network.NetworkInterface("NetworkInterface", location=az_location, resource_group_name=resource_group_name, ip_configurations=[azure.network.NetworkInterfaceIpConfigurationArgs( name="{}-{}-nic".format(project, env), subnet_id=app_subnet_id, private_ip_address_allocation="Dynamic", public_ip_address_id=public_ip_vm_id, )] )
`web_vm = azure.compute.LinuxVirtualMachine("WebVM", location=az_location, resource_group_name=resource_group_name, network_interface_ids=[network_interface.id], size=config.require('vm_size'), source_image_reference=azure.compute.VirtualMachineStorageImageReferenceArgs( publisher="Canonical", offer="UbuntuServer", sku=config.require('os_version'), version=config.require("vm_ubuntu_ver"), ), os_disk=azure.compute.LinuxVirtualMachineOsDiskArgs(
name="{}-{}-osDisk".format(project, env),