I was working for a customer, and the script was failing when a specific network interface was being used. The customer code was working just fine in the previous attempts. After some troubleshooting at the code level, we found out that the actual Network Interface was on a Failed state in Azure Portal, as depicted in the image below.
The solution was simple. First, go to Azure Resource Explorer and change to Read/Write (at the top of the page).
Navigate to the Subscription, Resource Group, expand Microsoft.Network, and in our case, expand networkinterfaces. Select the interface that it is in a failed state. Click on Edit.
The buttons will change. Click on Put, and then Get to check if the provisioningState changes to Succeeded.