Skip to content

[Draft] Support --what-if argument v2#32477

Open
wangzelin007 wants to merge 29 commits intoAzure:devfrom
wangzelin007:wzl/add-what-if-v2
Open

[Draft] Support --what-if argument v2#32477
wangzelin007 wants to merge 29 commits intoAzure:devfrom
wangzelin007:wzl/add-what-if-v2

Conversation

@wangzelin007
Copy link
Copy Markdown
Member

Related command

Description

Testing Guide

History Notes

[Component Name 1] BREAKING CHANGE: az command a: Make some customer-facing breaking change
[Component Name 2] az command b: Add some customer-facing feature


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 December 1, 2025 02:46
@azure-client-tools-bot-prd
Copy link
Copy Markdown

azure-client-tools-bot-prd bot commented Dec 1, 2025

️✔️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
️✔️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
Copy Markdown

azure-client-tools-bot-prd bot commented Dec 1, 2025

⚠️AzureCLI-BreakingChangeTest
⚠️network
rule cmd_name rule_message suggest_message
⚠️ 1006 - ParaAdd network vnet create cmd network vnet create added parameter export_bicep
⚠️ 1006 - ParaAdd network vnet create cmd network vnet create added parameter what_if
⚠️ 1006 - ParaAdd network vnet update cmd network vnet update added parameter export_bicep
⚠️ 1006 - ParaAdd network vnet update cmd network vnet update added parameter what_if
⚠️storage
rule cmd_name rule_message suggest_message
⚠️ 1006 - ParaAdd storage account create cmd storage account create added parameter export_bicep
⚠️ 1006 - ParaAdd storage account create cmd storage account create added parameter what_if
⚠️ 1006 - ParaAdd storage account network-rule add cmd storage account network-rule add added parameter export_bicep
⚠️ 1006 - ParaAdd storage account network-rule add cmd storage account network-rule add added parameter what_if
⚠️ 1006 - ParaAdd storage container create cmd storage container create added parameter export_bicep
⚠️ 1006 - ParaAdd storage container create cmd storage container create added parameter what_if
⚠️ 1006 - ParaAdd storage share create cmd storage share create added parameter export_bicep
⚠️ 1006 - ParaAdd storage share create cmd storage share create added parameter what_if
⚠️vm
rule cmd_name rule_message suggest_message
⚠️ 1006 - ParaAdd vm create cmd vm create added parameter export_bicep
⚠️ 1006 - ParaAdd vm create cmd vm create added parameter what_if
⚠️ 1006 - ParaAdd vm disk attach cmd vm disk attach added parameter export_bicep
⚠️ 1006 - ParaAdd vm disk attach cmd vm disk attach added parameter what_if
⚠️ 1006 - ParaAdd vm disk detach cmd vm disk detach added parameter export_bicep
⚠️ 1006 - ParaAdd vm disk detach cmd vm disk detach added parameter what_if
⚠️ 1006 - ParaAdd vm nic remove cmd vm nic remove added parameter export_bicep
⚠️ 1006 - ParaAdd vm nic remove cmd vm nic remove added parameter what_if
⚠️ 1006 - ParaAdd vm update cmd vm update added parameter export_bicep
⚠️ 1006 - ParaAdd vm update cmd vm update added parameter what_if

@yonzhan
Copy link
Copy Markdown
Collaborator

yonzhan commented Dec 1, 2025

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

@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 1, 2025

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
Copy Markdown
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 introduces support for the --what-if and --export-bicep arguments across multiple Azure CLI commands to enable preview of changes before execution. The implementation integrates with an external what-if service to analyze Azure CLI commands and predict their impact on Azure resources.

Key Changes:

  • New what_if.py module implementing the what-if analysis functionality with external service integration
  • Addition of --what-if and --export-bicep parameters to VM, storage, and network commands
  • Update to issue reporting URL in the resource formatter to use a specific GitHub template

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 27 comments.

Show a summary per file
File Description
src/azure-cli-core/azure/cli/core/what_if.py New module implementing what-if service integration with progress indicators and Bicep template conversion
src/azure-cli-core/azure/cli/core/commands/__init__.py Integration of what-if logic into command execution flow with supported command whitelist
src/azure-cli-core/azure/cli/core/commands/parameters.py Definition of reusable what_if and export_bicep parameter types
src/azure-cli/azure/cli/command_modules/vm/custom.py Addition of what_if and export_bicep parameters to VM command functions
src/azure-cli/azure/cli/command_modules/vm/_params.py Parameter registration for VM commands including create, update, disk operations, and NIC management
src/azure-cli/azure/cli/command_modules/storage/operations/fileshare.py Addition of what-if parameters to file share creation
src/azure-cli/azure/cli/command_modules/storage/operations/blob.py Addition of what-if parameters to container creation
src/azure-cli/azure/cli/command_modules/storage/operations/account.py Addition of what-if parameters to storage account operations
src/azure-cli/azure/cli/command_modules/storage/_params.py Parameter registration for storage commands
src/azure-cli/azure/cli/command_modules/network/aaz/latest/network/vnet/_update.py AAZ schema definition for vnet update what-if parameters
src/azure-cli/azure/cli/command_modules/network/aaz/latest/network/vnet/_create.py AAZ schema definition for vnet create what-if parameters
src/azure-cli/azure/cli/command_modules/network/_params.py Parameter registration for network vnet commands
src/azure-cli/azure/cli/command_modules/resource/_formatters.py Updated issue reporting URL to use specific GitHub template

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

Comment on lines +271 to +275
payload = {
"azcli_script": azcli_script,
"export_bicep": export_bicep,
"subscription_id": subscription_id
}
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

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

Potential information disclosure: The payload includes the full Azure CLI script and subscription ID. Ensure this is properly documented and users are aware of what information is being sent to the external service. Consider:

  1. Sanitizing sensitive information from commands (e.g., passwords, secrets)
  2. Adding clear documentation about data transmission
  3. Implementing data retention policies

Copilot uses AI. Check for mistakes.

# Check if command is in whitelist
if not self._is_command_supported_for_what_if(args):
error_msg = ("\"--what-if\" argument is not supported for this command.")
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

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

The error message format is inconsistent. Using f-string formatting with .format() style placeholders mixed in other parts of the code. This error should follow the same pattern as others:

error_msg = "\"--what-if\" argument is not supported for this command."

Or use consistent formatting throughout.

Copilot uses AI. Check for mistakes.
what_if_type = CLIArgumentType(
options_list=['--what-if'],
help="Preview the changes that will be made without actually executing the command. "
"This will call the what-if service to compare the current state with the expected state after execution.",
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

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

[nitpick] Documentation issue: The help text doesn't specify the argument type (boolean) or default value. Consider making it more explicit:

help="Preview the changes that will be made without actually executing the command. "
     "This will call the what-if service to compare the current state with the expected state after execution. "
     "Default: False",
Suggested change
"This will call the what-if service to compare the current state with the expected state after execution.",
"This will call the what-if service to compare the current state with the expected state after execution. "
"Type: boolean. Default: False.",

Copilot uses AI. Check for mistakes.
Comment on lines +155 to +156
except:
pass
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

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

The exception handling is too broad and suppresses all exceptions without logging. This could hide important errors during cleanup. Consider handling specific exception types or at least logging the error.

except Exception as ex:
    logger.warning("Failed to clear progress indicator: %s", str(ex))

Copilot uses AI. Check for mistakes.
Comment on lines +2277 to +2278
def detach_managed_data_disk(cmd, resource_group_name, vm_name, disk_name=None, force_detach=None, disk_ids=None,
what_if=False, export_bicep=False):
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

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

Unused parameters what_if and export_bicep in the function signature. Either use them or mark as intentionally unused.

Copilot uses AI. Check for mistakes.
Comment on lines +170 to +171
except:
pass
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

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

The same bare exception handling issue exists here. Use specific exception types or at least log the error:

except Exception as ex:
    logger.warning("Failed to clear progress indicator: %s", str(ex))

Copilot uses AI. Check for mistakes.
exclude_zones=None, align_regional_disks_to_vm_zone=None, wire_server_mode=None, imds_mode=None,
wire_server_access_control_profile_reference_id=None, imds_access_control_profile_reference_id=None,
key_incarnation_id=None, add_proxy_agent_extension=None):
key_incarnation_id=None, add_proxy_agent_extension=None, what_if=False, export_bicep=False):
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

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

Unused parameters in the function signature should be either removed or explicitly marked with a leading underscore to indicate they're intentionally unused. The what_if and export_bicep parameters are added but never used in the function body.

If these parameters are meant to be intercepted before the function is called, document this behavior or remove them from the signature.

Suggested change
key_incarnation_id=None, add_proxy_agent_extension=None, what_if=False, export_bicep=False):
key_incarnation_id=None, add_proxy_agent_extension=None):

Copilot uses AI. Check for mistakes.

def create_share(cmd, client, metadata=None, quota=None, fail_on_exist=False, timeout=None, **kwargs):
def create_share(cmd, client, metadata=None, quota=None, fail_on_exist=False, timeout=None,
what_if=False, export_bicep=False, **kwargs):
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

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

Unused parameters what_if and export_bicep in the function signature. Either use them or mark as intentionally unused.

Suggested change
what_if=False, export_bicep=False, **kwargs):
_what_if=False, _export_bicep=False, **kwargs):

Copilot uses AI. Check for mistakes.
metadata=None, public_access=None, fail_on_exist=False, timeout=None,
default_encryption_scope=None, prevent_encryption_scope_override=None):
default_encryption_scope=None, prevent_encryption_scope_override=None,
what_if=None, export_bicep=None):
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

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

Inconsistent parameter types: what_if and export_bicep should use consistent default values. In this file they default to None, while in other files they default to False. This inconsistency could lead to unexpected behavior when these parameters are checked.

Recommend using False as the default consistently across all functions.

Suggested change
what_if=None, export_bicep=None):
what_if=False, export_bicep=False):

Copilot uses AI. Check for mistakes.

def add_network_rule(cmd, client, resource_group_name, account_name, action='Allow', subnet=None,
vnet_name=None, ip_address=None, tenant_id=None, resource_id=None): # pylint: disable=unused-argument
vnet_name=None, ip_address=None, tenant_id=None, resource_id=None,
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

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

Trailing whitespace on this line should be removed.

Suggested change
vnet_name=None, ip_address=None, tenant_id=None, resource_id=None,
vnet_name=None, ip_address=None, tenant_id=None, resource_id=None,

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants