Skip to content

[Compute] az vmss lifecycle-hook/ lifecycle-hook-event: Add new command groups to support vmss lifecycle hooks - #33758

Merged
Julie Zhu (yanzhudd) merged 25 commits into
Azure:devfrom
william051200:lifecycle-hooks
Aug 14, 2026
Merged

[Compute] az vmss lifecycle-hook/ lifecycle-hook-event: Add new command groups to support vmss lifecycle hooks#33758
Julie Zhu (yanzhudd) merged 25 commits into
Azure:devfrom
william051200:lifecycle-hooks

Conversation

@william051200

@william051200 William (william051200) commented Jul 21, 2026

Copy link
Copy Markdown
Member

🤖 PR Validation — ⚠️ Review suggested

Breaking Changes Tests
⚠️ None ️✔️ 130/130
⚠️AzureCLI-BreakingChangeTest
⚠️vm
rule cmd_name rule_message suggest_message
⚠️ 1011 - SubgroupAdd vmss lifecycle-hook sub group vmss lifecycle-hook added
⚠️ 1011 - SubgroupAdd vmss lifecycle-hook-event sub group vmss lifecycle-hook-event added

Related command

az vmss lifecycle-hook add/list/remove/show/update
az vmss lifecycle-hook-event approve/list/reject/show/update

Description

Resolve #33652

aaz Azure/aaz#1046

Testing Guide

Refer to azure-cli\src\azure-cli\azure\cli\command_modules\vm\tests\latest\test_vm_commands.py:

  1. test_vmss_lifecycle_hook
  2. test_vmss_lifecycle_hook_event

az vmss lifecycle-hook-event approve/reject/update are not included in the test cases as they required live platform-generated event. Service team will be helping with the test locally.

History Notes

[Compute] az vmss lifecycle-hook/ lifecycle-hook-event: Add new command groups to support vmss lifecycle hooks


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 July 21, 2026 05:53
@william051200
William (william051200) requested a review from a team as a code owner July 21, 2026 05:53
@azure-client-tools-bot-prd

Copy link
Copy Markdown

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

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@william051200 William (william051200) changed the title {Compute} az vmss lifecycle-hooks &az vmss lifecycle-hooks-event: Add new command groups to support vmss lifecycle hooks {Compute} az vmss lifecycle-hooks/ lifecycle-hooks-event: Add new command groups to support vmss lifecycle hooks Jul 21, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot added the Auto-Assign Auto assign by bot label Jul 21, 2026
@william051200 William (william051200) changed the title {Compute} az vmss lifecycle-hooks/ lifecycle-hooks-event: Add new command groups to support vmss lifecycle hooks {Compute} az vmss lifecycle-hook/ lifecycle-hook-event: Add new command groups to support vmss lifecycle hooks Jul 21, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 new preview command groups under the vmss command module to manage VM Scale Set lifecycle hooks and to interact with platform-generated lifecycle hook events, along with scenario tests and recordings.

Changes:

  • Add az vmss lifecycle-hook commands (add/update/remove/show/list) backed by new custom implementations.
  • Add az vmss lifecycle-hook-event commands, including AAZ-generated list/show/update and custom wrappers for update/approve/reject with client-side validation.
  • Add scenario tests and a recording to validate core command behaviors.

Reviewed changes

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

Show a summary per file
File Description
src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_commands.py Adds scenario tests for lifecycle-hook and lifecycle-hook-event command groups.
src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_vmss_lifecycle_hook_event.yaml Adds recording for lifecycle-hook-event list scenario.
src/azure-cli/azure/cli/command_modules/vm/custom.py Implements lifecycle hook CRUD and lifecycle hook event update/approve/reject helpers.
src/azure-cli/azure/cli/command_modules/vm/commands.py Registers new command groups and wires validators.
src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vmss/lifecycle_hook_event/_update.py Adds AAZ-generated vmss lifecycle-hook-event update.
src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vmss/lifecycle_hook_event/_show.py Adds AAZ-generated vmss lifecycle-hook-event show.
src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vmss/lifecycle_hook_event/_list.py Adds AAZ-generated vmss lifecycle-hook-event list.
src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vmss/lifecycle_hook_event/init.py Exposes lifecycle_hook_event AAZ commands for loading.
src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vmss/lifecycle_hook_event/__cmd_group.py Registers the AAZ command group for lifecycle hook events.
src/azure-cli/azure/cli/command_modules/vm/_validators.py Adds validators for hook removal and lifecycle-hook-event update/action behaviors.
src/azure-cli/azure/cli/command_modules/vm/_params.py Adds argument definitions/enums for lifecycle hook and lifecycle hook event commands.
src/azure-cli/azure/cli/command_modules/vm/_help.py Adds help content for the new command groups/commands.

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

# AZURE CLI VM TEST DEFINITIONS
import json
import os
import datetime
Comment on lines +5123 to +5131
def _commit_vmss_lifecycle_hooks(cmd, resource_group_name, vmss_name, hooks, no_wait):
from .operations.vmss import VMSSCreate, convert_show_result_to_snake_case
vmss = get_vmss_modified_by_aaz(cmd, resource_group_name, vmss_name)
vmss = convert_show_result_to_snake_case(vmss)
vmss["lifecycle_hooks_profile"] = {"lifecycle_hooks": hooks}
vmss["resource_group"] = resource_group_name
vmss["vm_scale_set_name"] = vmss_name
vmss["no_wait"] = no_wait
return VMSSCreate(cli_ctx=cmd.cli_ctx)(command_args=vmss)
Comment on lines +3079 to +3082
helps['vmss lifecycle-hook-event'] = """
type: group
short-summary: Manage virtual machine scale set lifecycle hook events.
"""
@william051200 William (william051200) changed the title {Compute} az vmss lifecycle-hook/ lifecycle-hook-event: Add new command groups to support vmss lifecycle hooks [Compute] az vmss lifecycle-hook/ lifecycle-hook-event: Add new command groups to support vmss lifecycle hooks Jul 21, 2026
@yonzhan

Copy link
Copy Markdown
Collaborator

Compute

@william051200

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@william051200

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@a0x1ab

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@william051200

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@william051200

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@x-engineering-agent

Copy link
Copy Markdown
Contributor

Automated sensitive-information remediation ran on this pull request.

  • Detected categories: cloud identifier
  • Replaced with typed [REDACTED:category] placeholders in: no writable PR fields
  • Could not edit: file changes on a fork branch
  • Comment/review owners notified because Agent Assist cannot edit another user's text: none

If a credential was exposed, rotate or revoke it immediately. Detected values are never copied into this comment.

✅ Keep the redaction · ❌ Dispute the redaction

GitHub only supports a fixed reaction set, so 👍 represents ✅ and 👎 represents ❌. The bot-created reactions are only poll choices.


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

@william051200

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@microsoft-github-policy-service

Copy link
Copy Markdown
Contributor

🔔 Routing this PR to @Azure/act-observability-squad.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 14 changed files in this pull request and generated no new comments.

Suppressed comments (7)

src/azure-cli/azure/cli/command_modules/vm/custom.py:5245

  • instance_ids is accepted by vmss_lifecycle_hook_event_approve but never used (the validator resolves target_resource_ids). Removing the unused parameter avoids pylint noise and makes it clear instance-ids is handled in validation.
def vmss_lifecycle_hook_event_approve(cmd, resource_group_name, vmss_name, lifecycle_hook_event_name,
                                      target_resource_ids=None, instance_ids=None):

src/azure-cli/azure/cli/command_modules/vm/custom.py:5252

  • instance_ids is accepted by vmss_lifecycle_hook_event_reject but never used (the validator resolves target_resource_ids). Removing the unused parameter avoids pylint noise and makes it clear instance-ids is handled in validation.
def vmss_lifecycle_hook_event_reject(cmd, resource_group_name, vmss_name, lifecycle_hook_event_name,
                                     target_resource_ids=None, instance_ids=None):

src/azure-cli/azure/cli/command_modules/vm/_validators.py:2924

  • _resolve_vmss_lifecycle_hook_event_target_resources reads event['properties']['targetResources'] from an AAZ Show result, but it doesn't unregister global transforms like the custom lifecycle-hook-event commands do. If global transforms are enabled, the response keys may be snake_cased (e.g. target_resources), causing this to resolve an empty target list and potentially reject valid --instance-ids / approve/reject operations. Unregister transforms (and/or accept both key shapes) before parsing.
def _resolve_vmss_lifecycle_hook_event_target_resources(cmd, namespace):
    from azure.cli.core.azclierror import InvalidArgumentValueError
    from .aaz.latest.vmss.lifecycle_hook_event import Show as _lifecycleHookEventShow

    event = _lifecycleHookEventShow(cli_ctx=cmd.cli_ctx)(command_args={

src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:4729

  • Grammar: this comment should use present tense (the commands still require a platform-generated event).
    # Not including approve/reject/show and update --action-state as they required live platform-generated event

src/azure-cli/azure/cli/command_modules/vm/_help.py:3082

  • The vmss lifecycle-hook-event command group is registered as preview (is_preview=True), but the help short-summary doesn't indicate preview. This makes the help output inconsistent with the command registration and with vmss lifecycle-hook help.
helps['vmss lifecycle-hook-event'] = """
type: group
short-summary: Manage virtual machine scale set lifecycle hook events.
"""

src/azure-cli/azure/cli/command_modules/vm/_params.py:1187

  • The linked requirements for vmss lifecycle-hook-event update include escape hatches like --target-resources (raw targetResources[]) and --body (full PATCH payload), mutually exclusive with the higher-level flags. The custom command currently only exposes --action-state/--wait-until/--instance-ids, which prevents advanced scenarios (e.g., mixed target states) and diverges from the stated contract.
    with self.argument_context('vmss lifecycle-hook-event update') as c:
        c.argument('action_state', arg_type=get_enum_type(LifecycleHookActionState),
                   help="State of the lifecycle hook for the target resource. The customer can patch this property to "
                        "move the lifecycle hook to a terminal state.")
        c.argument('wait_until',
                   help='Specifies the exact UTC timestamp in ISO 8601 format till which the event would remain in '
                        'the current lifecycle state waiting for an action from the customer. Beyond this timestamp, '
                        'the platform will apply the defaultAction for the event.')

src/azure-cli/azure/cli/command_modules/vm/custom.py:5221

  • instance_ids is accepted by vmss_lifecycle_hook_event_update but never used in the function body. This can trigger pylint unused-argument warnings and is confusing since resolution happens in the validator via target_resource_ids. Consider removing it from the signature (the validator can still consume the CLI arg) or renaming to _instance_ids.

This issue also appears in the following locations of the same file:

  • line 5244
  • line 5251
def vmss_lifecycle_hook_event_update(cmd, resource_group_name, vmss_name, lifecycle_hook_event_name,
                                     action_state=None, wait_until=None, target_resource_ids=None, instance_ids=None):

@yanzhudd
Julie Zhu (yanzhudd) merged commit 48769a2 into Azure:dev Aug 14, 2026
53 checks passed
@william051200
William (william051200) deleted the lifecycle-hooks branch August 14, 2026 04:30
@a0x1ab Aditya Pujara (a0x1ab) added X Engineering Agent Reviewed Pull request reviewed by X Engineering Agent and removed azure-client-tools-agent labels Sep 2, 2026
@microsoft-github-policy-service

Copy link
Copy Markdown
Contributor

🔔 Routing this PR to @Azure/act-observability-squad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

act-observability-squad Auto-Assign Auto assign by bot Compute az vm/vmss/image/disk/snapshot X Engineering Agent Reviewed Pull request reviewed by X Engineering Agent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Add VMSS Lifecycle Hooks support to az vmss (preview)

6 participants