We are using Terraform IaC to maintain our azure infrastructure. We are trying to upgrade a function app from version 3 to 4, as part of it Azure will delete and recreate the function app. Delete and recreate will happen as part of the same terraform apply command. The execution is failing after the delete function app and before creating it. Azure is deleting the function app but not letting us to re-use the same name for re-creation. Any way to resolve this issue using terraform commands (Created a support ticket to Microsoft but their response is ‘this is normal expected behavior and asking us to use a diff name’ )
I’m assuming this is something similar to not being able to instantly reuse the name of a just-deleted S3 bucket in AWS.
As this is something restricted on the Azure side you’d either need to wait and re-run later (assuming you are able to reuse the name once it has fully cleaned up within Azure - note for AWS that can be 30 minutes or more, so might be similar for Azure) or as support mentioned use a different name. It isn’t something Terraform can do anything itself about as it is the cloud provider preventing the name being used.
If terraform let us to add some delay/wait between delete and create will resolve the issue (in case of azure we can reuse the name in 1 min). But I don’t know If there is any way to do it.
Typically this sort of problem is handled by adding retry logic inside the provider, because the provider’s job is to hide as much as possible the quirks of the underlying API to make it fit within Terraform Core’s expectations.
In this case it sounds like the requirement would be for the Azure provider to notice that the “create” API returned this particular error and politely retry for some reasonable amount of time before returning the error to you.
I don’t know how feasible that is in practice because I’m not familiar with this API, but I would suggest opening a feature request in the Azure provider’s GitHub repository (if there isn’t already a similar one open) to share the problem you encountered, so the provider team can consider possible ways to make this API appear more friendly to Terraform’s expectations.