Azure / azure-cli

Azure Command-Line Interface
MIT License
4.01k stars 2.98k forks source link

APIM gets stuck in soft-delete state #16138

Open pownkel opened 3 years ago

pownkel commented 3 years ago

Describe the bug A soft-delete feature was recently added to API management, and is only available through the preview version of the REST API. The documentation linked above states that using the azure CLI to delete an API Management instance will result in hard delete behavior. This is true, for the az apim delete command.

However, deleting the entire resource group with az group delete puts any existing APIM resources into the soft-deleted state, so those resources cannot be redeployed (due to naming collisions) until the deleted resource expires or is purged. The purge functionality is only available through the preview version of the REST API, so it seems like the new soft-delete shouldn't affect the CLI tool.

To Reproduce

  1. Create a new resource group
  2. Create an API management instance inside that resource group
  3. Use az group delete to delete the resource grop
  4. Use the REST API to list soft-deleted services, and notice that the API management instance is listed

Expected behavior Using az group delete has the same affect on the api management instance as az apim delete

Environment summary CLI version: 2.14.2 (installed with apt-get) OS version: Windows 10 build 19042.630 Shell type: Bash on windows (WSL 1)

ghost commented 3 years ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @miaojiang.

Issue Details
**Describe the bug** A [soft-delete feature](https://docs.microsoft.com/en-us/azure/api-management/soft-delete) was recently added to API management, and is only available through the preview version of the REST API. The documentation linked above states that using the azure CLI to delete an API Management instance will result in hard delete behavior. This is true, for the `az apim delete` command. However, deleting the entire resource group with `az group delete` puts any existing APIM resources into the soft-deleted state, so those resources cannot be redeployed (due to naming collisions) until the deleted resource expires or is purged. The purge functionality is only available through the preview version of the REST API, so it seems like the new soft-delete shouldn't affect the CLI tool. **To Reproduce** 1. Create a new resource group 2. Create an API management instance inside that resource group 3. Use `az group delete` to delete the resource grop 4. Use the REST API to [list soft-deleted services](https://docs.microsoft.com/en-us/rest/api/apimanagement/2020-06-01-preview/deletedservices/listbysubscription), and notice that the API management instance is listed **Expected behavior** Using `az group delete` has the same affect on the api management instance as `az apim delete` **Environment summary** CLI version: 2.14.2 (installed with apt-get) OS version: Windows 10 build 19042.630 Shell type: Bash on windows (WSL 1)
Author: pownkel
Assignees: -
Labels: `API Management`, `Service Attention`, `needs-triage`, `question`
Milestone: -
yungezz commented 3 years ago

route to appropriate team

miaojiang commented 3 years ago

Thanks for reporting the issue. We will review.

cc @KedarJoshi @RupengLiu

piizei commented 3 years ago

This totally broke our infrastructure automation for several projects 😠

usrme commented 3 years ago

A soft-deletion also occurs if you explicitly decide to delete the APIM instance from a resource group through the Portal. This should be communicated more clearly.

dannyrc commented 3 years ago

This is causing me a real headache.

ilanRosenbaum commented 3 years ago

Same here, constantly having to rename stuff just to avoid this "feature"

anon65856 commented 3 years ago

Thanks for reporting the issue. We will review.

cc @KedarJoshi @RupengLiu

We've just deployed an APIM instance using API version Microsoft.ApiManagement/service@2019-12-01 - We're seeing soft delete applied when we've deleted this resource through the portal. Was under the impression this was only a feature in the new preview version 2020-06-01-preview ?

Seems the 2019-12-01 version does not include the property "restore" so unsure why it's applying soft delete?

ks-ascendum commented 3 years ago

This is a crappy feature. Been fighting this for a few hours trying to purge hidden resources.

GPetrites commented 3 years ago

Just stumbled across this today while testing a Bicep template to deploy APIM. So after learning Bicep/ARM to create resources, and PowerShell/CLI to also...create and delete resources. we now need to figure out how to use REST to purge APIM instances?

How many different technologies do we need to learn to support Azure?

stvdilln commented 3 years ago

re out how to use REST to purge APIM instances? az rest --method delete --header "Accept=applicaiton/json" -u 'https://management.azure.com/subscriptions/{SubscriptionId}/providers/Microsoft.ApiManagement/locations/{eastus}/deletedservices/{api name}?api-version=2020-06-01-preview'

GPetrites commented 3 years ago

That worked, but it was much more painful that having a button on the portal or a CLI or PowerShell command.

miaojiang commented 3 years ago

Thank you all for the feedback. We are considering adding an option to az apim delete to control whether soft delete should be applied.

kieranross89 commented 3 years ago

re out how to use REST to purge APIM instances? az rest --method delete --header "Accept=applicaiton/json" -u 'https://management.azure.com/subscriptions/{SubscriptionId}/providers/Microsoft.ApiManagement/locations/{eastus}/deletedservices/{api name}?api-version=2020-06-01-preview'

This works in removing a soft deleted instance but I always get a 404/Service Not FoundError Not Found({"error":{"code":"ServiceNotFound","message":"Api service does not exist: testapimkjr","details":null,"innerError":null}})

GPetrites commented 3 years ago

@miaojiang More important to the "az apim delete" options, we need CLI (and PowerShell) commands that we can use to discover, purge and restore soft-deleted APIM instances. APIMs will get deleted using a variety of mechanisms, including deleting via the portal. Currently, the only option we have to do this is using the REST API. I'm glad to discover "az rest" can be used for that, but it's not the best option as it requires us to maintain knowledge of yet another toolset.

safari137 commented 3 years ago

We've just deployed an APIM instance using API version Microsoft.ApiManagement/service@2019-12-01 - We're seeing soft delete applied when we've deleted this resource through the portal. Was under the impression this was only a feature in the new preview version 2020-06-01-preview ?

Seems the 2019-12-01 version does not include the property "restore" so unsure why it's applying soft delete?

Still waiting for an answer on this question? Why are we forced to use a preview feature on production?

bmedlin commented 3 years ago

Come on Microsoft - we depend on you. This 'feature' is poorly documented & half-implemented. This approach comes at a real cost to us, your partners. Do better!

nirzaf commented 3 years ago

What the hell is going on Microsoft, When a DevOps deletes something we know What we are doing, Don't try to treat us like a amateur common user, take of this damn bloody feature please

jochenvw commented 3 years ago

+1 - me and my customer encountered the same challenge - looking forward to a better experience

dotNetCory commented 3 years ago

I too am stuck, I've spent days building up my arm templates, I already have to maintain and try and keep the devs onboard with your 2 CLI versions, now I have to build up a REST request?

Its annoying, because I have to get all the IDs to build up the URL, to point to the resource, at least in CLI I can set context. Its insane that you don't support your own stuff!

Molter commented 2 years ago

Soon this issue will complete a whole year. This is a really bad design choice, soft delete being on preview should be optional and not lock you behind the rest api.

Walluce commented 2 years ago

Why would you activate a feature that doesn't have support in portal or the az command line? It's shocking to have to use the REST API to delete an APIM, especially when it worked previously

Walluce commented 2 years ago

Can I please report this "feature" as a defect?

Gordonby commented 2 years ago

KeyVault allows a boolean property to be set enableSoftDelete when the resource is created. This defaults to on, but allows the service to opt out of the SoftDelete capability at the point of creation.

I'd love to see this same logic applied to APIM.

Nightreaver commented 2 years ago

Still an issue! How can I delete it?

az rest --method delete --header "Accept=application/json" -u 'https://management.azure.com/subscriptions/[subscriptionid]/providers/Microsoft.ApiManagement/deletedservices/[myapi]?api-version=2020-06-01-preview'
Bad Request({"error":{"code":"DisallowedResourceOperation","message":"The operation 'delete' on resource type 'deletedservices' is disallowed."}})
dannyrc commented 2 years ago

This is beyond a joke now, I managed to purge a key vault in soft delete yesterday using the CLI, why not implement the same functionality for APIM? 🤯

Paul121GW commented 2 years ago

@Nightreaver, try using '/locations/{location}/' in your https-string:

https://management.azure.com/subscriptions/[subscriptionid]/providers/Microsoft.ApiManagement/locations/[location]/deletedservices/...

mcquiggd commented 2 years ago

Wasted a day on this - how on earth was this feature silently enabled, without requiring an opt-in, without an easy way to purge the soft-deleted instances, which leads to a day searching through out-of-date Microsoft docs that gives partial clues...?

DexterPOSH commented 2 years ago

Another day wasted for me as well.

IstvanCsVarga commented 2 years ago

Another day which could've been productive work.

orendin commented 2 years ago

Very poor developer experience, Microsoft. Who came up with that??

The solution for me was to first list the deleted instance to get the required details and for the purge, using az rest like pointed out by stvdilln above.

Login using az login in the console.

Then az rest --method get --header "Accept=application/json" -u 'https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.ApiManagement/deletedservices?api-version=2021-08-01' to list the details of the soft deleted apim service.

Then delete it using the following, making sure to add the correct location in the url (e.g. westeurope or eastus): az rest --method delete --header "Accept=application/json" -u 'https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.ApiManagement/locations/{location}/deletedservices/{apim-name}?api-version=2020-06-01-preview'

Surprisingly, this took only a second to execute. Much less than the hour I wasted trying to figure out what the hell is going on and how to fix it...

ulluoink commented 1 year ago

still not fixed and still non reaction this is a shame

ulluoink commented 1 year ago

Thank you all for the feedback. We are considering adding an option to az apim delete to control whether soft delete should be applied.

still considering? after over a year?

ajs5710 commented 1 year ago

Based on the amount of time several of the features surrounding the apims have been left in preview I wouldn't be surprised if Azure rolls back the whole apims feature so you're probably better off switching to some other provider or using a third party if you want apims functionality.

dannyrc commented 1 year ago

Complete joke this still isn't sorted

ulluoink commented 1 year ago

@miaojiang @RupengLiu what's wrong with you guys.

What ist the actual state of this bug? Why don't you just fix ????!!!!?

aminnowise commented 1 year ago

still not fixed

Meertman commented 5 months ago

Since the az apim deletedservice purge (https://learn.microsoft.com/en-us/cli/azure/apim/deletedservice?view=azure-cli-latest#az-apim-deletedservice-purge) operation is present now, I think this issue can be closed, right?

brad-dawson commented 1 month ago

When attempting to restore a soft-deleted API-M, for the Standard V2 sku, I had to add single quotes around the URL, and use double quotes in the JSON body:

az rest --method put --header "Accept=applicaiton/json" -u 'https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{apimResourceName}?api-version=2023-03-01-preview' --body '{"properties": { "publisherEmail": "email@contoso.com", "publisherName": "Contoso", "restore": true }, "sku": { "name": "StandardV2", "capacity": 1 }, "location": "East US" }'

The documentation only helped a little bit and the actual request needed to be adjusted from what was stated here: