From 9bd702ef3714e8ace2d638745d8d175d9335932e Mon Sep 17 00:00:00 2001 From: Zim Kalinowski Date: Tue, 4 Sep 2018 09:41:41 +0800 Subject: [PATCH] vm size idempotence (#45108) --- .../cloud/azure/azure_rm_virtualmachine.py | 7 ++++++ .../tasks/virtualmachine.yml | 25 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine.py b/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine.py index a63623d308d..470f941db23 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine.py @@ -901,6 +901,13 @@ class AzureRMVirtualMachine(AzureRMModuleBase): changed = True vm_dict['properties']['storageProfile']['osDisk']['diskSizeGB'] = self.os_disk_size_gb + if self.vm_size and \ + self.vm_size != vm_dict['properties']['hardwareProfile']['vmSize']: + self.log('CHANGED: virtual machine {0} - size '.format(self.name)) + differences.append('VM size') + changed = True + vm_dict['properties']['hardwareProfile']['vmSize'] = self.vm_size + update_tags, vm_dict['tags'] = self.update_tags(vm_dict.get('tags', dict())) if update_tags: differences.append('Tags') diff --git a/test/integration/targets/azure_rm_virtualmachine/tasks/virtualmachine.yml b/test/integration/targets/azure_rm_virtualmachine/tasks/virtualmachine.yml index 23d807559fb..335beea2f36 100644 --- a/test/integration/targets/azure_rm_virtualmachine/tasks/virtualmachine.yml +++ b/test/integration/targets/azure_rm_virtualmachine/tasks/virtualmachine.yml @@ -192,6 +192,31 @@ - assert: that: not output.changed +- name: Resize VM + azure_rm_virtualmachine: + resource_group: "{{ resource_group }}" + name: "{{ vm_name1 }}" + vm_size: Standard_A1 + storage_account: "{{ storage_account }}" + storage_container: "{{ vm_name1 }}" + storage_blob: "{{ vm_name1 }}.vhd" + admin_username: adminuser + admin_password: Password123! + short_hostname: testvm + os_type: Linux + network_interfaces: "{{ vm_name1 }}" + image: + offer: UbuntuServer + publisher: Canonical + sku: 16.04-LTS + version: latest + register: output + +- assert: + that: + - output.changed + - output.ansible_facts.azure_vm.properties.hardwareProfile.vmSize == "Standard_A1" + - name: Delete VM azure_rm_virtualmachine: resource_group: "{{ resource_group }}"