Identify if VM is running on Azure Cloud or Azure Stack Hub

Sachin Laddha 1 Reputation point
2020-12-03T09:42:11.353+00:00

I need to identify if a VM is running on Azure cloud or Azure stack hub.

MSFT documentation says that the IMDS service is not available on Azure Stack Hub VMs. Call to IMDS on Azure Stack Hub VM returns 500 error code and message {"Message":"Error in config data"}. It does not return 404.

Azure Cloud documentation says that IMDS can return 500 error code on Azure Cloud VMs
https://video2.skills-academy.com/en-us/azure/virtual-machines/windows/instance-metadata-service#errors-and-debugging

Can someone please confirm if we need to rely on error code i.e. 500 and error message "Error in config data" both to know if a VM is running on AZS?
Is there any other way ?

Best regards,
Sachin

Azure Stack Hub
Azure Stack Hub
An extension of Azure for running apps in an on-premises environment and delivering Azure services in a datacenter.
188 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. TravisCragg-MSFT 5,681 Reputation points Microsoft Employee
    2020-12-04T02:28:49.863+00:00

    To my knowledge there is a not a good way to determine this. I like the trick that you have, but it does seem like a poor workaround. Another thing that you can try to check the version of the Azure Agent in the VM, depending upon when the images were downloaded, Azure Stack should use a past version of the agent.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.