Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't create host in resource group from gallery image which belongs to another resource group #160

Open
milanzelenka opened this issue Sep 7, 2022 · 2 comments

Comments

@milanzelenka
Copy link

Hi,

We have problem when creating VM in resource group from image gallery in another resource group.

Steps to reproduce:

  1. create new compute resource
  2. create image in compute resource
    Image UUID: gallery://PUBX-RHEL-8 (which is created in azure resource group rg-azeun-X)
  3. create VM in resource group rg-azeun-X (which is the same as resource group of image gallery) => everything works fine and VM is created.
  4. createVM is in another resource group than resource group of image gallery => VM creation failed with error: "Failed to create a compute XY (Azure Resource Manager) instance app01-test-rhel8-d.azure.pubx: \"message\": \"MsRestAzure::AzureOperationError: InvalidParameter: The value of parameter imageReference.publisher is invalid."

IMHO problem is that image_reference is fetched from VM resource group name and not from original resource group name which is image belongs to.

Changing of rg_name to fixed string with original resource group name 'rg-azeun-X' in file managed_vm.rb on line 87 (in function define_image()) helps and VM is created successfully.

https://github.com/apuntamb/foreman_azure_rm/blob/6e6d4ec4d578bf637af913404fc15aa8a4e348dd/app/models/concerns/foreman_azure_rm/vm_extensions/managed_vm.rb#L87

           image_reference.id = custom_image.id
         when 'gallery'
           image_reference = ComputeModels::ImageReference.new
-          image_reference.id = sdk.fetch_gallery_image_id(rg_name, image_id)
+          image_reference.id = sdk.fetch_gallery_image_id('rg-azeun-X', image_id)
         else
           image_reference = nil
         end

@evanlaar
Copy link

evanlaar commented Jun 2, 2023

Hi,

we're also running into this issue.
The same issue also exists with custom:// images.

Maybe the image id should be stored in the database when defining it,
instead of trying to rebuild it every time the image is used by foreman ?

Furthermore Azure compute galleries (gallery:// images) can optionally be shared across tenants and subscriptions
and can even be made public (Currently in preview; see here)
so I think storing the image id in the database might be the only solution ?

@chris1984
Copy link
Member

Yes, that is a good plan forward, I can make an issue on our sprint board and start to work on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants