How can i use the latest image from an image gallery

I’m using azurerm_linux_virtual_machine to create a VM in our environment using source images we have in our own Gallery.

I know you can define “source_image_id” and give it a complete pointer to a specific version of the image you have in your gallery, but i would like to know if there is a way to specify the latest revision of the image.

So in a production environment you would obviously use a specific known good version, in order to do testing my thoughts are to have a devops pipeline that builds using latest image so we can verify everything is ok.

So for example, here is a rough outline of my current code

resource "azurerm_linux_virtual_machine" "main" {
  name                = "test-vm"
  resource_group_name = module.resource_group.testname
  location            = var.testlocation

  admin_username                  = "adminuser"
  computer_name                   = "testhost”
  network_interface_ids           = [azurerm_network_interface.main.id]
  size                            = "Standard_D2_v2"
  source_image_id                 = "/subscriptions/…/Microsoft.Compute/galleries/Mycg/images/redhat-8/1.5”
  admin_password                  = “xxxxxxxx”
  disable_password_authentication = false

Ideally i would like something like this

source_image_id                 = "/subscriptions/…/Microsoft.Compute/galleries/Mycg/images/redhat-8/latest”

Does anyone have a solution they use for this or a direction i can look in.

Thanks