Not able to use custom image from the Compute Gallery (formerly known as Shared Image Gallery)

Hello,

I would like to use our custom made image (various OS) from the Azure compute Gallery (formerly known as Shared Image Gallery) for machine creation. All details such as ID, sku, provider etc. obtained via Azure CLI.

However when I use respective block in virtual machine definition supreme block:
"source_image_reference {
publisher = “OurCompanyName”
offer = “OurCustomName”
sku = “OurCustomSKU”
version = “latest”
}"

I am getting this error:
“Failure sending request: StatusCode=404 – Original Error: Code=“PlatformImageNotFound” Message=“The platform image ‘Kyndryl:rh91-1:rh91-1:latest’ is not available. Verify that all fields in the storage profile are correct. For more details about storage profile information, please refer to StorageProfile Class (Microsoft.Azure.Management.Compute.Models) - Azure for .NET Developers | Microsoft Learn” Target=“imageReference””

I have find out that this method cannot be used for Compute Gallery (Shared Image Gallery) anymore because there has been changes made in Compute API which the block is using for API calls and therefore it is not able to properly reference the custom image, see:

As alternative I was suggested to use “storage_image_reference” block instead, however when I used that I have got this error:
“Error: Unsupported block type”
“Blocks of type “storage_image_reference” are not expected here.”

So my question is what is currently functional solution to use custom image from Compute Gallery (Shared Image Gallery) when creating a new vm with Terraform? Thank you.

Update: I seem to have been successful after using this combination:

1/ Data Source: azurerm_shared_image
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/shared_image

"data “azurerm_shared_image” “example” {

  • name = “my-image”
  • gallery_name = “my-image-gallery”
  • resource_group_name = “example-resources”
    }"

2/ Argument Reference: source_image_id
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/windows_virtual_machine.html

“source_image_id = data.azurerm_shared_image.example.id”

However, now I’m getting this ‘os_profile’ error. Apparently there is a conflict with our custom image with the admin user already predefined:
“Error: creating Linux Virtual Machine: (Name “dev-001-rh91” / Resource Group “rg-RV-Kyndryl-Delivery-kcl-eastus-001”): compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=400 – Original Error: Code=“InvalidParameter” Message=“Parameter ‘osProfile’ is not allowed.” Target=“osProfile””

Contrary to this, the ‘admin_username’ argument must be specified in the ‘os_profile’ block according to the TF, otherwise an error is returned:
“The argument “admin_username” is required, but no definition was found.”

Any suggestion now please?

@martin-hlousek_kyndr , did you ever figure this out?