Skip to content

Conversation

@william051200
Copy link
Member

Related command

az vm secret add
az vm secret list
az vm secret remove

Description

Migration from mgmt.compute to aaz-based

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 12, 2026 02:06
@azure-client-tools-bot-prd
Copy link

azure-client-tools-bot-prd bot commented Jan 12, 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
️✔️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

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

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

@yonzhan
Copy link
Collaborator

yonzhan commented Jan 12, 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 migrates the az vm secret command group (add, list, remove) from the legacy mgmt.compute SDK to the new aaz-based implementation. The migration updates the internal implementation while maintaining the same external API surface.

Changes:

  • Added aaz-based helper functions: get_vm_by_aaz(), set_vm_by_aaz(), and updated get_vm_to_update_by_aaz()
  • Migrated three secret management commands to use aaz dictionaries instead of SDK models
  • Updated property access patterns from snake_case to camelCase to match AAZ naming conventions

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

Comment on lines +3243 to +3327
'certificate_store': certificate_store,
'certificate_url': certificate
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

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

The dictionary key should be 'certificateStore' (camelCase) to match the AAZ naming convention used elsewhere in this migration. The current snake_case 'certificate_store' is inconsistent with the camelCase pattern used in other parts of the code (e.g., 'certificateUrl', 'sourceVault', 'vaultCertificates').

Suggested change
'certificate_store': certificate_store,
'certificate_url': certificate
'certificateStore': certificate_store,
'certificateUrl': certificate

Copilot uses AI. Check for mistakes.
Comment on lines +3243 to +3327
'certificate_store': certificate_store,
'certificate_url': certificate
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

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

The dictionary key should be 'certificateUrl' (camelCase) to match the AAZ naming convention used elsewhere in this migration. The current snake_case 'certificate_url' is inconsistent with the camelCase pattern used in other parts of the code (e.g., 'certificateStore' on line 3243, 'sourceVault', 'vaultCertificates').

Suggested change
'certificate_store': certificate_store,
'certificate_url': certificate
'certificateStore': certificate_store,
'certificateUrl': certificate

Copilot uses AI. Check for mistakes.
},
'vaultCertificates': [vault_cert]
}
vm.get('osProfile', {}).get('secrets', []).append(vault_secret_group)
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

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

Bug: When 'secrets' key doesn't exist in osProfile, vm.get('osProfile', {}).get('secrets', []) returns a new empty list, and appending to that list won't modify the vm dictionary. This line should either initialize the secrets list if it doesn't exist before appending, or use a pattern like: if 'secrets' not in vm['osProfile']: vm['osProfile']['secrets'] = []; vm['osProfile']['secrets'].append(vault_secret_group)

Copilot uses AI. Check for mistakes.
if keyvault:
keyvault = keyvault.lower()
keyvault_matched = [x for x in to_keep if x.source_vault and x.source_vault.id.lower() == keyvault]
keyvault_matched = [x for x in to_keep if x.get("sourceVault", {}).get('id', '').lower() == keyvault]
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

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

Inconsistent quote usage: The key "sourceVault" uses double quotes while 'id' uses single quotes. For consistency with the rest of the codebase, use either all double quotes or all single quotes within the same dictionary access chain.

Suggested change
keyvault_matched = [x for x in to_keep if x.get("sourceVault", {}).get('id', '').lower() == keyvault]
keyvault_matched = [x for x in to_keep if x.get('sourceVault', {}).get('id', '').lower() == keyvault]

Copilot uses AI. Check for mistakes.
@yanzhudd yanzhudd changed the title {Compute} az vm secret: Migrate command group to aaz-based implementation {Compute} az vm secret: Migrate command group to aaz-based implementation Jan 13, 2026
if x.get('sourceVault', {}).get('id', '').lower() == keyvault.lower()), None)
if vault_secret_group:
vault_secret_group.vault_certificates.append(vault_cert)
vault_secret_group.get('vaultCertificates', []).append(vault_cert)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please note that the get(key, default_value) function returns the default value when the key does not exist in the dictionary. However, this default value is not automatically added to the dictionary.

Suggested change
vault_secret_group.get('vaultCertificates', []).append(vault_cert)
certs = vault_secret_group.get('vaultCertificates', [])
certs.append(vault_cert)
vault_secret_group['vaultCertificates'] = certs

certificate = cert_info.secret_id

if not _is_linux_os(vm):
if not _is_linux_os_by_aaz(vm):
Copy link
Contributor

Choose a reason for hiding this comment

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

the _is_linux_os_by_aaz function is based on the snake case, so we might need to convert the vm to snake case first

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.

4 participants