Skip to content

Conversation

@zunyangc
Copy link
Collaborator

@zunyangc zunyangc commented Dec 18, 2025

SUMMARY

Fix #1208. Add support for Azure delete_option on VM-attached disks, aligned with ARM behavior.

  • OS disk: os_disk_delete_option (Delete | Detach) (Note: Default to Detach if no specify, except ephemeral OS disks which must always be Delete)
  • Data disks: per-disk delete_option (Delete | Detach) (Note: Default to Detach if no specify)
  • Default NIC behavior: Default NIC created by the VM (when no network_interface_names provided) are deleted with the VM)
ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

plugins/modules/azure_rm_virtualmachine.py

ADDITIONAL INFORMATION
  • remove_on_absent remains available when VM is removed via ARM (state: absent).
  • Spot evictions trigger VM deletion outside Ansible; Azure applies the VM model's delete_option settings for OS and data disks.
  • Network interfaces are handled according to Azure native behavior: default NICs created by the VM are removed with the VM; standalone or user-supplied NICs remain managed by the Network API (Future work: adding delete_option for azure_rm_networkinterface.py.

References: https://learn.microsoft.com/en-us/rest/api/compute/virtual-machines/create-or-update?view=rest-compute-2025-02-01&tabs=HTTP#definitions

@zunyangc zunyangc added enhancement New feature or request work in In trying to solve, or in working with contributors labels Dec 18, 2025
@zunyangc zunyangc added ready_for_review The PR has been modified and can be reviewed and merged and removed work in In trying to solve, or in working with contributors labels Dec 22, 2025
@zunyangc zunyangc marked this pull request as ready for review December 22, 2025 03:48
@zunyangc
Copy link
Collaborator Author

Hi @magodo, pipeline test result passed. Ready to merge, thanks!

@zunyangc zunyangc requested a review from magodo December 22, 2025 03:48
type: str
choices:
- Delete
- Detach
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we also specify default: Detach here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Azure already treats deleteOption as Detach by default when the field is omitted in the VM model. If we set default: Detach in the module’s argument spec, the parameter becomes implicitly “set” even when the user doesn’t specify it. As a result, if a user manually changes deleteOption to Delete (e.g., in the portal/CLI) and later re-runs the playbook without explicitly setting os_disk_delete_option / data_disks[].delete_option, the module would revert it back to Detach.

And so I think a safer way is to document Detach as the Azure default, like this

- Azure default to Detach if no specified.

Comment on lines 656 to 673
os_disk_delete_option:
description:
- Specifies the delete behavior for the VM's OS disk when the VM is deleted.
- When set to C(Delete), the OS disk will be removed automatically during VM deletion.
- When set to C(Detach), the OS disk will be preserved.
type: str
choices:
- Delete
- Detach
nic_delete_option:
description:
- Specifies the delete behavior for the VM's NIC when the VM is deleted.
- When set to C(Delete), the NIC will be removed automatically during VM deletion.
- When set to C(Detach), the NIC will be preserved.
type: str
choices:
- Delete
- Detach
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shall we also specify the default here?

Comment on lines 1605 to 1606
if dd_arg.get('delete_option') is None:
continue
Copy link
Collaborator

Choose a reason for hiding this comment

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

This needs to be checked in case the remote has set the delete_option to Delete.

choices:
- Delete
- Detach
nic_delete_option:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why isn't this a per NIC option?

@zunyangc zunyangc added work in In trying to solve, or in working with contributors and removed ready_for_review The PR has been modified and can be reviewed and merged labels Jan 2, 2026
@zunyangc zunyangc marked this pull request as draft January 2, 2026 00:23
@zunyangc zunyangc changed the title Fix #1208: Adding delete_option for data disk, os disk, nic Fix #1208: Adding delete_option for data disk and os disk Jan 9, 2026
@zunyangc zunyangc removed the work in In trying to solve, or in working with contributors label Jan 9, 2026
@zunyangc zunyangc added the ready_for_review The PR has been modified and can be reviewed and merged label Jan 9, 2026
@zunyangc zunyangc marked this pull request as ready for review January 9, 2026 06:52
@zunyangc
Copy link
Collaborator Author

zunyangc commented Jan 9, 2026

Hi @magodo, pipeline test result passed. Ready to merge, thanks!

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

Labels

enhancement New feature or request ready_for_review The PR has been modified and can be reviewed and merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

azure_rm_virtualmachine option for auto delete all resources connected to created VM

3 participants