Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VirtualMachine update to allow creation from snapshot image #1816

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

p3ck
Copy link
Collaborator

@p3ck p3ck commented Jan 29, 2025

SUMMARY

VirtualMachine supports swapping an exisiting VM to use a snapshot. This update allows for it to create the VM from the beginning from a snapshot.

Also includes a small update to azure_rm_virtualmachine_info to report details on os_disk. Snapshot creation is only supported with managed disks.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

plugins/modules/azure_rm_virtualmachine.py
plugins/modules/azure_rm_virtualmachine_info.py

ADDITIONAL INFORMATION
Example playbook to create VM from Snapshot...

- name: Get snapshot info
  azure.azcollection.azure_rm_snapshot_info:
    resource_group: "{{ resource_group_name }}"
    name: "{{ snapshot_name }}"
  register: snapshot_info

- name: Create Managed disk from Snapshot
  azure.azcollection.azure_rm_manageddisk:
    name: "{{ vm_from_snapshot_disk_name }}"
    location: "{{ snapshot_info.state[0].location }}"
    resource_group: "{{ resource_group_name }}"
    create_option: copy
    source_uri: "{{ snapshot_info.state[0].id }}"
    storage_account_type: "{{ snapshot_info.state[0].sku.name }}"
  register: snapshot_disk

- name: Create VM
  azure.azcollection.azure_rm_virtualmachine:
    resource_group: "{{ resource_group_name }}"
    name: "{{ vm_from_snapshot_name }}"
    network_interfaces: "{{ network_interface }}"
    managed_disk_type: "{{ vm_managed_disk_type }}"
    swap_os_disk:
      os_disk_id: "{{ snapshot_disk.state.id }}"
    vm_size: "{{ vm_size }}"

VirtualMachine supports swapping an exisiting VM to use a snapshot.
This update allows for it to create the VM from the beginning from a
snapshot.
@p3ck p3ck requested review from Fred-sun and xuzhang3 January 29, 2025 20:05
@@ -2283,6 +2296,7 @@ def exec_module(self, **kwargs):
vm_resource.license_type = self.license_type

if self.vm_identity is not None:
current_user_assigned_identities_dict = {}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I noticed a linting error where this variable could possibly be referenced without having been defined.

@p3ck
Copy link
Collaborator Author

p3ck commented Feb 4, 2025

@Fred-sun @xuzhang3 ping? Thanks

@Fred-sun Fred-sun added enhancement New feature or request ready_for_review The PR has been modified and can be reviewed and merged medium_priority Medium priority labels Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request medium_priority Medium priority 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.

3 participants