Skip to content

az vm delete Command Does Not Return an Error When the Specified Resource Group or Virtual Machine Does Not Exist #33794

Description

@pavithra11dr

Describe the bug

When executing the az vm delete command with a non-existent virtual machine name and/or resource group, the command completes successfully without returning an error, warning, or non-zero exit code. This behaviour may mislead users and automation workflows into assuming that the deletion operation was successful, even though the target resource was never present.

Related command

az vm delete --resource-group pav -n pavithra

Errors

It does not return any error

Issue script & Debug output

pavithra [ ~ ]$ az vm delete --resource-group pav -n pavithra --debug
cli.knack.cli: Command arguments: ['vm', 'delete', '--resource-group', 'pav', '-n', 'pavithra', '--debug']
cli.knack.cli: init debug log:
Enable color in terminal.
cli.knack.cli: Event: Cli.PreExecute []
cli.knack.cli: Event: CommandParser.OnGlobalArgumentsCreate [<function CLILogging.on_global_arguments at 0x7ff784827740>, <function OutputProducer.on_global_arguments at 0x7ff78452be20>, <function CLIQuery.on_global_arguments at 0x7ff78456d260>]
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableCreate []
cli.azure.cli.core: Using packaged command index for profile 'latest'.
cli.azure.cli.core: Found installed extension 'ml' (azext_mlv2).
cli.azure.cli.core: Blending packaged core index with local extension index.
cli.azure.cli.core: Modules found from index for 'vm': ['azure.cli.command_modules.vm']
cli.azure.cli.core: Loading command modules...
cli.azure.cli.core: Loaded command modules in parallel:
cli.azure.cli.core: Name Load Time Groups Commands
cli.azure.cli.core: vm 0.300 61 224
cli.azure.cli.core: Total (1) 0.303 61 224
cli.azure.cli.core: These extensions are not installed and will be skipped: ['azext_ai_examples', 'azext_next']
cli.azure.cli.core: Loading extensions:
cli.azure.cli.core: Name Load Time Groups Commands Directory
cli.azure.cli.core: Total (0) 0.000 0 0
cli.azure.cli.core: Loaded 61 groups, 224 commands.
cli.azure.cli.core: Found a match in the command table.
cli.azure.cli.core: Raw command : vm delete
cli.azure.cli.core: Command table: vm delete
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableTruncate [<function AzCliLogging.init_command_file_logging at 0x7ff78430e2a0>]
cli.azure.cli.core.azlogging: metadata file logging enabled - writing logs to '/home/pavithra/.azure/commands/2026-07-27.06-38-58.vm_delete.1308.log'.
az_command_data_logger: command args: vm delete --resource-group {} -n {} --debug
cli.knack.cli: Event: CommandInvoker.OnPreArgumentLoad [<function register_global_subscription_argument..add_subscription_parameter at 0x7ff78434af20>]
cli.azure.cli.core.profiles._shared: Traceback (most recent call last):
File "/usr/lib64/az/lib/python3.12/site-packages/azure/cli/core/profiles/_shared.py", line 437, in _get_attr
op = import_module(full_mod_path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/importlib/init.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 1387, in _gcd_import
File "", line 1360, in _find_and_load
File "", line 1310, in _find_and_load_unlocked
File "", line 488, in _call_with_frames_removed
File "", line 1387, in _gcd_import
File "", line 1360, in _find_and_load
File "", line 1324, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'azure.mgmt.compute.v2024_03_03'

cli.knack.cli: Event: CommandInvoker.OnPostArgumentLoad []
cli.knack.cli: Event: CommandInvoker.OnPostCommandTableCreate [<function register_ids_argument..add_ids_arguments at 0x7ff78434ba60>, <function register_global_policy_argument..add_global_policy_argument at 0x7ff78434bba0>, <function register_cache_arguments..add_cache_arguments at 0x7ff78434bc40>, <function register_upcoming_breaking_change_info..update_breaking_change_info at 0x7ff78434bce0>]
cli.knack.cli: Event: CommandInvoker.OnCommandTableLoaded []
cli.knack.cli: Event: CommandInvoker.OnPreParseArgs []
cli.knack.cli: Event: CommandInvoker.OnPostParseArgs [<function OutputProducer.handle_output_argument at 0x7ff78452bec0>, <function CLIQuery.handle_query_parameter at 0x7ff78456d300>, <function register_ids_argument..parse_ids_arguments at 0x7ff78434bb00>]
Are you sure you want to perform this operation? (y/n): y
urllib3.util.retry: Converted retries value: 1 -> Retry(total=1, connect=None, read=None, redirect=None, status=None)
urllib3.connectionpool: Starting new HTTPS connection (1): login.microsoftonline.com:443
urllib3.connectionpool: https://login.microsoftonline.com:443 "GET /common//v2.0/.well-known/openid-configuration HTTP/1.1" 200 1728
msal.application: Broker enabled? None
cli.azure.cli.core.auth.credential_adaptor: CredentialAdaptor.get_token: scopes=('https://management.core.windows.net//.default',), kwargs={}
cli.azure.cli.core.auth.msal_credentials: CloudShellCredential.acquire_token: scopes=['https://management.core.windows.net//.default'], kwargs={}
urllib3.connectionpool: Starting new HTTP connection (1): localhost:50342
urllib3.connectionpool: http://localhost:50342 "POST /oauth2/token HTTP/1.1" 200 3236
msal.token_cache: event={
"authority_type": "CLOUDSHELL",
"client_id": "04b07795-8ddb-461a-bbee-02f9e1bf7b46",
"data": {},
"response": {
"access_token": "",
"client_info": "eyJ1aWQiOiAiZWUzYTM2ZTYtYjdhMy00MzMzLTlhOTYtYTE5ZjQwNTdkNGY1IiwgInV0aWQiOiAiMTZiM2MwMTMtZDMwMC00NjhkLWFjNjQtN2VkYTA4MjBiNmQzIn0=",
"expires_in": 3518,
"id_token_claims": "
",
"token_type": "Bearer"
},
"scope": [
"https://management.core.windows.net//.default"
],
"token_endpoint": "https://login.microsoftonline.com/common/oauth2/v2.0/token"
}
cli.azure.cli.core.sdk.policies: Request URL: 'https://management.azure.com/subscriptions/eb5cca67-d660-477a-ac9a-12de78532a35/resourceGroups/pav/providers/Microsoft.Compute/virtualMachines/pavithra?api-version=2024-11-01'
cli.azure.cli.core.sdk.policies: Request method: 'DELETE'
cli.azure.cli.core.sdk.policies: Request headers:
cli.azure.cli.core.sdk.policies: 'x-ms-client-request-id': 'd8a30a4a-8985-11f1-926c-00155dd9c586'
cli.azure.cli.core.sdk.policies: 'CommandName': 'vm delete'
cli.azure.cli.core.sdk.policies: 'ParameterSetName': '--resource-group -n --debug'
cli.azure.cli.core.sdk.policies: 'User-Agent': 'AZURECLI/2.87.0 (RPM) azsdk-python-core/1.39.0 Python/3.12.9 (Linux-6.1.146.1-microsoft-standard-x86_64-with-glibc2.38) cloud-shell/1.0'
cli.azure.cli.core.sdk.policies: 'Authorization': '*****'
cli.azure.cli.core.sdk.policies: Request body:
cli.azure.cli.core.sdk.policies: This request has no body
urllib3.connectionpool: Starting new HTTPS connection (1): management.azure.com:443
urllib3.connectionpool: https://management.azure.com:443 "DELETE /subscriptions/eb5cca67-d660-477a-ac9a-12de78532a35/resourceGroups/pav/providers/Microsoft.Compute/virtualMachines/pavithra?api-version=2024-11-01 HTTP/1.1" 204 0
cli.azure.cli.core.sdk.policies: Response status: 204
cli.azure.cli.core.sdk.policies: Response headers:
cli.azure.cli.core.sdk.policies: 'Cache-Control': 'no-cache'
cli.azure.cli.core.sdk.policies: 'Pragma': 'no-cache'
cli.azure.cli.core.sdk.policies: 'Expires': '-1'
cli.azure.cli.core.sdk.policies: 'x-ms-ratelimit-remaining-subscription-deletes': '199'
cli.azure.cli.core.sdk.policies: 'x-ms-ratelimit-remaining-subscription-global-deletes': '2999'
cli.azure.cli.core.sdk.policies: 'x-ms-request-id': '6ab7fe7f-34de-48ef-9f23-e1bcdf8f57d9'
cli.azure.cli.core.sdk.policies: 'x-ms-correlation-request-id': '6ab7fe7f-34de-48ef-9f23-e1bcdf8f57d9'
cli.azure.cli.core.sdk.policies: 'x-ms-routing-request-id': 'EASTUS2:20260727T063901Z:6ab7fe7f-34de-48ef-9f23-e1bcdf8f57d9'
cli.azure.cli.core.sdk.policies: 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains'
cli.azure.cli.core.sdk.policies: 'X-Content-Type-Options': 'nosniff'
cli.azure.cli.core.sdk.policies: 'X-Cache': 'CONFIG_NOCACHE'
cli.azure.cli.core.sdk.policies: 'X-MSEdge-Ref': 'Ref A: 1A4D99E3073B4AE19FDF10C963DC4D5E Ref B: SG2AA1070301060 Ref C: 2026-07-27T06:39:01Z'
cli.azure.cli.core.sdk.policies: 'Date': 'Mon, 27 Jul 2026 06:39:00 GMT'
cli.azure.cli.core.sdk.policies: Response content:
cli.azure.cli.core.sdk.policies:
cli.knack.cli: Event: CommandInvoker.OnTransformResult [<function _resource_group_transform at 0x7ff78434aca0>, <function _x509_from_base64_to_hex_transform at 0x7ff78434ad40>]
cli.knack.cli: Event: CommandInvoker.OnFilterResult []
cli.knack.cli: Event: Cli.SuccessfulExecute []
cli.knack.cli: Event: Cli.PostExecute [<function AzCliLogging.deinit_cmd_metadata_logging at 0x7ff78430e520>]
az_command_data_logger: exit code: 0
cli.main: Command ran in 3.447 seconds (init: 0.071, invoke: 3.376)
telemetry.main: Begin splitting cli events and extra events, total events: 1
telemetry.main: Finish splitting cli events and extra events, cli events: 1
telemetry.save: Save telemetry record of length 4182 in cache file under /home/pavithra/.azure/telemetry/20260727063901736
telemetry.main: Begin creating telemetry upload process.
telemetry.process: Creating upload process: "/usr/bin/python3.12 /usr/lib/az/lib/python3.12/site-packages/azure/cli/telemetry/init.py /home/pavithra/.azure /home/pavithra/.azure/telemetry/20260727063901736"
telemetry.process: Return from creating process 1321
telemetry.main: Finish creating telemetry upload process.
pavithra [ ~ ]$

Expected behavior

CLI should return an error stating RG or VM name not found under the subscription

Environment Summary

pavithra [ ~ ]$ az --version
azure-cli 2.87.0 *

core 2.87.0 *
telemetry 1.1.0

Extensions:
ml 2.43.0
ssh 2.0.9

Dependencies:
msal 1.36.0
azure-mgmt-resource 24.0.0

Python location '/usr/bin/python3.12'
Config directory '/home/pavithra/.azure'
Extensions directory '/home/pavithra/.azure/cliextensions'
Extensions system directory '/usr/lib/python3.12/site-packages/azure-cli-extensions'

Python (Linux) 3.12.9 (main, Jun 2 2026, 15:06:48) [GCC 13.2.0]

Legal docs and information: aka.ms/AzureCliLegal

You have 2 update(s) available. They will be updated with the next build of Cloud Shell.
pavithra [ ~ ]$

Additional context

This behaviour is observed in version 2.87.0, 2.88 but the same command returns expected error on CLI version 2.67

Activity

  1. added
    bugThis issue requires a change to an existing behavior in the product in order to be resolved.
    on Jul 27, 2026
  2. azure-client-tools-bot-prd commented on Jul 27, 2026

    @azure-client-tools-bot-prd

    Hi pavithra11dr,

    2.87.0 is not the latest Azure CLI(2.88.0).

    If you haven't already attempted to do so, please upgrade to the latest Azure CLI version by following https://learn.microsoft.com/en-us/cli/azure/update-azure-cli.

  3. yonzhan commented on Jul 27, 2026

    @yonzhan
    Collaborator

    Thank you for opening this issue, we will look into it.

  4. x-engineering-agent commented on Jul 27, 2026

    @x-engineering-agent
    Contributor

    Bug Analysis

    az vm delete --resource-group <rg> -n <vm> completes successfully (exit code 0, no error/warning) even when the specified resource group and/or VM name do not exist. The debug log shows the underlying ARM DELETE request is issued directly to the (non-existent) resource; Azure Resource Manager's DELETE verb is idempotent and returns 204 No Content for a resource that doesn't exist, so the SDK/CLI layer sees a "successful" response and reports nothing to the user.

    Reproduction

    az vm delete --resource-group pav -n pavithra --debug
    

    Reported on azure-cli 2.87.0 (current latest is 2.88.0); this is a client-side reporting gap, not version-specific.

    Expected behavior: the command should detect that the target resource group/VM does not exist (e.g., check existence first, or inspect the response) and surface a clear error/warning with a non-zero exit code instead of silently "succeeding", to avoid misleading users and automation relying on the exit code.

    Suggested fix location: src/azure-cli/azure/cli/command_modules/vm/custom.py (the delete_vm/vm delete implementation) — add an existence check (e.g., via resource_client or a GET before DELETE) and raise a ResourceNotFoundError (or similar) when the RG/VM is missing, mirroring how other az vm subcommands validate resource existence.

    Use this EXACT PR title: [VM] Fix #33794: az vm delete: return error when resource group or VM does not exist

    PR title & description format (required)

    This repo enforces a PR format (guide). Please author the PR exactly as follows or CI's Check the Format of Pull Request Title and Content will fail.

    Use this EXACT PR title (copy verbatim, do not reword):

    [VM] Fix #33794: `az vm delete`: return error when resource group or VM does not exist
    

    Keep the backticks around the command and the Fix #33794: prefix. You may only adjust the wording after the command (the final summary) if the fix changes; the [VM] prefix, issue link, and backticked command must stay.

    Description — follow the PR template and fill in:

    • Link the issue — start the Description with a closing keyword so the PR auto-links and closes it: Fixes #33794.
    • Related command — the az ... command this affects.
    • Description (mandatory) — why the bug happens, what you changed, and the resulting behavior.
    • Testing Guide — example command(s) showing the fix works.
    • History Notes — leave the title to drive the history note, or add extra lines in the same format (component in brackets + the command in backticks), e.g. [VM] `az <command>`: <note>.
    • Keep the template checklist and tick the items you've satisfied.

    Posted by agent-assist (autonomous bug-fix pipeline).

  5. removed
    questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that
    on Jul 27, 2026
  6. added this to the Backlog milestone on Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Auto-AssignAuto assign by botAuto-ResolveAuto resolve by botAzure CLI TeamThe command of the issue is owned by Azure CLI teamComputeaz vm/vmss/image/disk/snapshotact-observability-squadbugThis issue requires a change to an existing behavior in the product in order to be resolved.customer-reportedIssues that are reported by GitHub users external to the Azure organization.

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions