Skip to content

Commit

Permalink
Azure rm virtualmachineimage info latest (#617)
Browse files Browse the repository at this point in the history
* virtualmachineimage_info: add support for version="latest"

* Add test case for latest in virtualmachineimage_info

* Fix visual indent in virtualmachineimage_info
  • Loading branch information
nbr23 authored Aug 31, 2021
1 parent c5eaaa6 commit e93565b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
19 changes: 14 additions & 5 deletions plugins/modules/azure_rm_virtualmachineimage_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,25 @@ def exec_module(self, **kwargs):
def get_item(self):
item = None
result = []
versions = None

try:
item = self.compute_client.virtual_machine_images.get(self.location,
self.publisher,
self.offer,
self.sku,
self.version)
versions = self.compute_client.virtual_machine_images.list(self.location,
self.publisher,
self.offer,
self.sku,
top=1,
orderby='name desc')
except CloudError:
pass

if self.version == 'latest':
item = versions[-1]
else:
for version in versions:
if version.name == self.version:
item = version

if item:
result = [self.serialize_obj(item, 'VirtualMachineImage', enum_modules=AZURE_ENUM_MODULES)]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,15 @@

- assert:
that: output['vmimages'] | length > 0

- name: Get facts for a specific image's latest version
azure_rm_virtualmachineimage_info:
location: "{{ location }}"
publisher: OpenLogic
offer: CentOS
sku: '7.5'
version: 'latest'
register: output

- assert:
that: output['vmimages'] | length == 1

0 comments on commit e93565b

Please sign in to comment.