Skip to content

azure_rm_virtualmachine option for auto delete all resources connected to created VM #1208

Open
@toutas

Description

@toutas

I could not find a similar issue for azure_rm_virtualmachine

SUMMARY

creating a virtual machine using azure_rm_virtualmachine does not allow you to set flags on associated resources (like data/os disks, nics) that tell those resources to be deleted when the virtual machine itself is deleted. I would like functionality for this, similar to what has been added to.

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

azure_rm_virtualmachine

ADDITIONAL INFORMATION

Cleaning up resources from deleted virtual machines, especially spot machines, is somewhat of a pain in the ass if the associated virtual machine has been created using azure_rm_virtualmachine (and thus without auto delete). At worst it is required to go through the azure portal to check which resources associated with the deleted VM were not removed alongside it. Adding this functionality will lower the amount of labor required to delete resources that should have the same lifetime as the VM, and will make it a lot more manageable for spot eviction handling

- name: Create a VM with OS and multiple data managed disks -- autodelete
  azure_rm_virtualmachine:
    resource_group: myResourceGroup
    name: testvm001
    vm_size: Standard_D4
    managed_disk_type: Standard_LRS
    admin_username: "{{ username }}"
    ssh_public_keys:
      - path: /home/adminUser/.ssh/authorized_keys
        key_data: < insert your ssh public key here... >
    image:
      offer: 0001-com-ubuntu-server-focal
      publisher: canonical
      sku: 20_04-lts-gen2
      version: latest
    data_disks:
      - lun: 0
        managed_disk_id: "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myDisk"
      - lun: 1
        disk_size_gb: 128
        managed_disk_type: Premium_LRS
        deleteOption: Delete <------- suggested addition

https://learn.microsoft.com/en-us/azure/virtual-machines/delete?tabs=rest2%2Ccli3%2Cportal4%2Cportal5

I am unfamiliar with the API used, but the link above shows the functionality as part of the REST API/CLI/etc

Metadata

Metadata

Assignees

No one assigned

    Labels

    holdThe problem holds for a particular reasonmedium_priorityMedium priorityquestionFurther information is requestedwork inIn trying to solve, or in working with contributors

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions