Resource Group location for a VM resource

meoncloud 21 Reputation points
2020-11-19T07:44:20.607+00:00

I have a VM resource say which is in uswest and it is part of a resource group in the useast. When I make a rest api call to get the VM , how will I know that the VM is created in uswest but the resource group it is part of is in useast. My intent is to get the location of the resource group a resource belongs to.Is there a specific API /property that can help with this info ?

Azure Cloud Services
Azure Cloud Services
An Azure platform as a service offer that is used to deploy web and cloud applications.
669 questions
0 comments No comments
{count} votes

Accepted answer
  1. JessicaH-MSFT 246 Reputation points Microsoft Employee
    2020-11-19T19:17:57.1+00:00

    In order to query the location of the Resource Group, you'll need to use Resource Group - Get, the response from this call will provide you with the Resource group's location:

    GET https://management.azure.com/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}?api-version=2020-06-01  
    

    To get the location of a VM you can use the Virtual Machine - Get call:

    GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}?api-version=2020-06-01  
    

    All the information you're looking to query will be available by using a combination of these calls but there is currently not a single call that will return the response exactly as you're looking for so this will need to be accomplished programatically.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful