Retrieve latest azurerm_image - Sort by number

Hi,

I’m using the azurerm_image with a regex matching the desired image/s. I also add the sort_descending argument in an attempt to get the latest version of the image.

The problem here is that if the images are, for example, named like the following:

Image-1
Image-2
Image-3
Image-4
Image-5
Image-6
Image-7
Image-8
Image-9
Image-10

Where Image-10 is the latest version of the image, it doesn’t return that, instead it returns Image-9 as the result. I’m guessing it’s a lexicographically sort going on here, and that’s why I’m seeing this behaviour.

Is there any way, in which I can get it to sort on a number order instead, by using the azurerm_image data source? Otherwise, is there a way in achieveing this with perhaps the azurerm_images in combination with some built in function or some other way to sort the results?

I’m looking for a way to retrieve the latest image, without having to change the naming, tags or any other properties of it.

Otherwise, how have you solved this? What is your approach to being able to create multiple images and version them and then being able to retrieve the latest one? Byt tags, any other property or something completely else? I could be adding tags to the image I guess (which is being generated by Packer), but then I would need to delete the “latest” tag from the old image, in favour for the new latest? I would rather like to avoid any additional kind of configuration/logic/setup etc. and also avoid third party stuff if possible.

Any design input would be appreciated here. :slight_smile:

Thank you in advance!

One thing to do, could be to implement an Azure image gallery, but again, I’m curious to know if the sorting problem can be solved.