Skip to content

Conversation

@william051200
Copy link
Member

@william051200 william051200 commented Jan 22, 2026

Related command

az vm create
az vmss create

Description

Resolve #32682

Warning displayed when image is marked as "scheduledfordeprecation":
image

Testing Guide

History Notes


This checklist is used to make sure that common guidelines for a pull request are followed.

Copilot AI review requested due to automatic review settings January 22, 2026 07:49
@azure-client-tools-bot-prd
Copy link

azure-client-tools-bot-prd bot commented Jan 22, 2026

️✔️AzureCLI-FullTest
️✔️acr
️✔️latest
️✔️3.12
️✔️3.13
️✔️acs
️✔️latest
️✔️3.12
️✔️3.13
️✔️advisor
️✔️latest
️✔️3.12
️✔️3.13
️✔️ams
️✔️latest
️✔️3.12
️✔️3.13
️✔️apim
️✔️latest
️✔️3.12
️✔️3.13
️✔️appconfig
️✔️latest
️✔️3.12
️✔️3.13
️✔️appservice
️✔️latest
️✔️3.12
️✔️3.13
️✔️aro
️✔️latest
️✔️3.12
️✔️3.13
️✔️backup
️✔️latest
️✔️3.12
️✔️3.13
️✔️batch
️✔️latest
️✔️3.12
️✔️3.13
️✔️batchai
️✔️latest
️✔️3.12
️✔️3.13
️✔️billing
️✔️latest
️✔️3.12
️✔️3.13
️✔️botservice
️✔️latest
️✔️3.12
️✔️3.13
️✔️cdn
️✔️latest
️✔️3.12
️✔️3.13
️✔️cloud
️✔️latest
️✔️3.12
️✔️3.13
️✔️cognitiveservices
️✔️latest
️✔️3.12
️✔️3.13
️✔️compute_recommender
️✔️latest
️✔️3.12
️✔️3.13
️✔️computefleet
️✔️latest
️✔️3.12
️✔️3.13
️✔️config
️✔️latest
️✔️3.12
️✔️3.13
️✔️configure
️✔️latest
️✔️3.12
️✔️3.13
️✔️consumption
️✔️latest
️✔️3.12
️✔️3.13
️✔️container
️✔️latest
️✔️3.12
️✔️3.13
️✔️containerapp
️✔️latest
️✔️3.12
️✔️3.13
️✔️core
️✔️latest
️✔️3.12
️✔️3.13
️✔️cosmosdb
️✔️latest
️✔️3.12
️✔️3.13
️✔️databoxedge
️✔️latest
️✔️3.12
️✔️3.13
️✔️dls
️✔️latest
️✔️3.12
️✔️3.13
️✔️dms
️✔️latest
️✔️3.12
️✔️3.13
️✔️eventgrid
️✔️latest
️✔️3.12
️✔️3.13
️✔️eventhubs
️✔️latest
️✔️3.12
️✔️3.13
️✔️feedback
️✔️latest
️✔️3.12
️✔️3.13
️✔️find
️✔️latest
️✔️3.12
️✔️3.13
️✔️hdinsight
️✔️latest
️✔️3.12
️✔️3.13
️✔️identity
️✔️latest
️✔️3.12
️✔️3.13
️✔️iot
️✔️latest
️✔️3.12
️✔️3.13
️✔️keyvault
️✔️latest
️✔️3.12
️✔️3.13
️✔️lab
️✔️latest
️✔️3.12
️✔️3.13
️✔️managedservices
️✔️latest
️✔️3.12
️✔️3.13
️✔️maps
️✔️latest
️✔️3.12
️✔️3.13
️✔️marketplaceordering
️✔️latest
️✔️3.12
️✔️3.13
️✔️monitor
️✔️latest
️✔️3.12
️✔️3.13
️✔️mysql
️✔️latest
️✔️3.12
️✔️3.13
️✔️netappfiles
️✔️latest
️✔️3.12
️✔️3.13
️✔️network
️✔️latest
️✔️3.12
️✔️3.13
️✔️policyinsights
️✔️latest
️✔️3.12
️✔️3.13
️✔️postgresql
️✔️latest
️✔️3.12
️✔️3.13
️✔️privatedns
️✔️latest
️✔️3.12
️✔️3.13
️✔️profile
️✔️latest
️✔️3.12
️✔️3.13
️✔️rdbms
️✔️latest
️✔️3.12
️✔️3.13
️✔️redis
️✔️latest
️✔️3.12
️✔️3.13
️✔️relay
️✔️latest
️✔️3.12
️✔️3.13
️✔️resource
️✔️latest
️✔️3.12
️✔️3.13
️✔️role
️✔️latest
️✔️3.12
️✔️3.13
️✔️search
️✔️latest
️✔️3.12
️✔️3.13
️✔️security
️✔️latest
️✔️3.12
️✔️3.13
️✔️servicebus
️✔️latest
️✔️3.12
️✔️3.13
️✔️serviceconnector
️✔️latest
️✔️3.12
️✔️3.13
️✔️servicefabric
️✔️latest
️✔️3.12
️✔️3.13
️✔️signalr
️✔️latest
️✔️3.12
️✔️3.13
️✔️sql
️✔️latest
️✔️3.12
️✔️3.13
️✔️sqlvm
️✔️latest
️✔️3.12
️✔️3.13
️✔️storage
️✔️latest
️✔️3.12
️✔️3.13
️✔️synapse
️✔️latest
️✔️3.12
️✔️3.13
️✔️telemetry
️✔️latest
️✔️3.12
️✔️3.13
️✔️util
️✔️latest
️✔️3.12
️✔️3.13
️✔️vm
️✔️latest
️✔️3.12
️✔️3.13

@azure-client-tools-bot-prd
Copy link

Hi @william051200,
Since the current milestone time is less than 7 days, this pr will be reviewed in the next milestone.

@azure-client-tools-bot-prd
Copy link

azure-client-tools-bot-prd bot commented Jan 22, 2026

️✔️AzureCLI-BreakingChangeTest
️✔️Non Breaking Changes

@yonzhan
Copy link
Collaborator

yonzhan commented Jan 22, 2026

Thank you for your contribution! We will review the pull request and get back to you soon.

@github-actions
Copy link

The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR.

Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions).
After that please run the following commands to enable git hooks:

pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds image deprecation status validation for az vm create and az vmss create commands to warn users when they attempt to use images marked as "ScheduledForDeprecation". This addresses security and compliance risks associated with deprecated images, particularly critical for the Windows Server 2022 .NET 6 deprecation scenario.

Changes:

  • Added a new validation function _validate_image_deprecation_status that checks if a marketplace image is scheduled for deprecation
  • Integrated the validation into the _validate_vm_create_storage_profile function to warn users during VM/VMSS creation
  • The validation queries the image deprecation status via Azure API and displays a warning when the status is "ScheduledForDeprecation"

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 2691 to 2718
def _validate_image_deprecation_status(cmd, namespace):
from .aaz.latest.vm.image import Show as _ImageShow
from ._actions import _get_latest_image_version

if namespace.os_version.lower() == 'latest':
latest_version = _get_latest_image_version(
cmd.cli_ctx,
location=namespace.location,
publisher=namespace.os_publisher,
offer=namespace.os_offer,
sku=namespace.os_sku,
)
else:
latest_version = namespace.os_version

image = _ImageShow(cli_ctx=cmd.cli_ctx)(command_args={
'location': namespace.location,
'publisher': namespace.os_publisher,
'offer': namespace.os_offer,
'sku': namespace.os_sku,
'version': latest_version,
})

if not image:
return

if image.get('imageDeprecationStatus', {}).get('imageState') == 'ScheduledForDeprecation':
logger.warning('The selected image is scheduled for deprecation.')
Copy link

Copilot AI Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function assumes that namespace has os_version, os_publisher, os_offer, and os_sku attributes, but these are only populated when the image is specified as a URN (publisher:offer:sku:version) or URN alias. For other image types like managed custom images, shared gallery images, community gallery images, or VHD URIs, these attributes won't exist and will cause an AttributeError. Add a guard check at the beginning of the function to return early if these attributes don't exist.

Copilot uses AI. Check for mistakes.
})

if not image:
return
Copy link

Copilot AI Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the trailing space at the end of the return statement.

Suggested change
return
return

Copilot uses AI. Check for mistakes.
Comment on lines 2706 to 2716
image = _ImageShow(cli_ctx=cmd.cli_ctx)(command_args={
'location': namespace.location,
'publisher': namespace.os_publisher,
'offer': namespace.os_offer,
'sku': namespace.os_sku,
'version': latest_version,
})

if not image:
return

Copy link

Copilot AI Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API call to _ImageShow could potentially fail (e.g., network issues, invalid parameters, image not found). While there's a check for empty response, there's no try-except block to handle potential exceptions. Consider wrapping the API calls in a try-except block to gracefully handle errors and avoid crashing the validation process.

Suggested change
image = _ImageShow(cli_ctx=cmd.cli_ctx)(command_args={
'location': namespace.location,
'publisher': namespace.os_publisher,
'offer': namespace.os_offer,
'sku': namespace.os_sku,
'version': latest_version,
})
if not image:
return
try:
image = _ImageShow(cli_ctx=cmd.cli_ctx)(command_args={
'location': namespace.location,
'publisher': namespace.os_publisher,
'offer': namespace.os_offer,
'sku': namespace.os_sku,
'version': latest_version,
})
except Exception as err: # pylint: disable=broad-except
logger.warning('Failed to retrieve image deprecation status: %s', err)
return
if not image:
return

Copilot uses AI. Check for mistakes.
Comment on lines 2691 to 2718
def _validate_image_deprecation_status(cmd, namespace):
from .aaz.latest.vm.image import Show as _ImageShow
from ._actions import _get_latest_image_version

if namespace.os_version.lower() == 'latest':
latest_version = _get_latest_image_version(
cmd.cli_ctx,
location=namespace.location,
publisher=namespace.os_publisher,
offer=namespace.os_offer,
sku=namespace.os_sku,
)
else:
latest_version = namespace.os_version

image = _ImageShow(cli_ctx=cmd.cli_ctx)(command_args={
'location': namespace.location,
'publisher': namespace.os_publisher,
'offer': namespace.os_offer,
'sku': namespace.os_sku,
'version': latest_version,
})

if not image:
return

if image.get('imageDeprecationStatus', {}).get('imageState') == 'ScheduledForDeprecation':
logger.warning('The selected image is scheduled for deprecation.')
Copy link

Copilot AI Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new validation function _validate_image_deprecation_status lacks test coverage. Similar validation functions in this module have corresponding tests in test_vm_defaults.py (e.g., test_vm_validator_retrieve_image_info_cross_subscription). Consider adding test coverage for this new deprecation status validation to ensure it works correctly for both 'latest' version and specific version scenarios.

Copilot uses AI. Check for mistakes.

def _validate_image_deprecation_status(cmd, namespace):
from .aaz.latest.vm.image import Show as _ImageShow
from ._actions import _get_latest_image_version
Copy link

Copilot AI Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import of _get_latest_image_version from ._actions is redundant as it's already imported at the module level (line 27). Remove this duplicate import.

Suggested change
from ._actions import _get_latest_image_version

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Auto-Assign Auto assign by bot Compute az vm/vmss/image/disk/snapshot

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Azure CLI: Throw Warning when user tries to deploy VM/VMSS using a deprecating image

4 participants