diff --git a/src/azure-cli/azure/cli/command_modules/vm/_validators.py b/src/azure-cli/azure/cli/command_modules/vm/_validators.py index e36ceeedc7f..abcff98b50f 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/vm/_validators.py @@ -821,8 +821,11 @@ def _check_subnet(s): if (subnet_is_id and vnet) or (not subnet_is_id and not vnet): raise CLIError("incorrect usage: --subnet ID | --subnet NAME --vnet-name NAME") + from azure.cli.command_modules.network.aaz.latest.network.vnet import Show as VirtualNetworkShow + api_version = VirtualNetworkShow._aaz_info['version'] subnet_exists = \ - check_existence(cmd.cli_ctx, subnet, rg, 'Microsoft.Network', 'subnets', vnet, 'virtualNetworks') + check_existence(cmd.cli_ctx, subnet, rg, 'Microsoft.Network', 'subnets', + vnet, 'virtualNetworks', api_version=api_version) if subnet_is_id and not subnet_exists: raise CLIError("Subnet '{}' does not exist.".format(subnet)) diff --git a/src/azure-cli/azure/cli/command_modules/vm/_vm_utils.py b/src/azure-cli/azure/cli/command_modules/vm/_vm_utils.py index 04a1a92901a..7c256a1dd25 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/_vm_utils.py +++ b/src/azure-cli/azure/cli/command_modules/vm/_vm_utils.py @@ -73,7 +73,7 @@ def log_pprint_template(template): def check_existence(cli_ctx, value, resource_group, provider_namespace, resource_type, - parent_name=None, parent_type=None): + parent_name=None, parent_type=None, api_version=None): # check for name or ID and set the type flags from azure.cli.core.commands.client_factory import get_mgmt_service_client from azure.core.exceptions import HttpResponseError @@ -93,7 +93,9 @@ def check_existence(cli_ctx, value, resource_group, provider_namespace, resource parent_path = '' resource_name = id_parts['name'] resource_type = id_parts.get('type', resource_type) - api_version = _resolve_api_version(cli_ctx, provider_namespace, resource_type, parent_path) + + if not api_version: + api_version = _resolve_api_version(cli_ctx, provider_namespace, resource_type, parent_path) try: resource_client.get(rg, ns, parent_path, resource_type, resource_name, api_version)