0

I am trying to find the resource group allocated to a VM in azure using nodejs.

I am using the below link as my reference https://learn.microsoft.com/en-us/samples/azure-samples/resource-manager-node-resources-and-groups/resource-manager-node-resources-and-groups/#list-groups

The below gets resource group details If I provide resourceGroupName and subscription_Id https://learn.microsoft.com/en-us/rest/api/resources/resource-groups/get

But I only have VM name and subsciption_Id

Any help appreciated. Thanks in advance

Aravind Reddy
  • 353
  • 4
  • 18

1 Answers1

2

Take a look here: https://learn.microsoft.com/en-us/samples/azure-samples/compute-node-manage-vm/compute-node-manage-vm/

This shows an example where you can list all VMs in a subsription.

 computeClient.virtualMachines.listAll(function (err, result)

The will result in the VM ID which will have the RG name in it (TESTRG9397 in this example).

id: '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/TESTRG9397/providers/Microsoft.Compute/virtualMachines/testvm3365'

You will have to parse the ID to get it but then you will have RG and SUB so you can call

computeClient.virtualMachines.get(resourceGroupName, vmName, function (err, result))
Ken W - Zero Networks
  • 3,533
  • 1
  • 13
  • 18
  • Thanks for that, this totally makes sense. But If I have of thousands of VM's listing all and parsing resource ID from that might not be an optimal case. I see python3 provides a direct function called ```get_rg_of_vm(vm_name)```, Sad that node doesn't have one like that – Aravind Reddy Jun 18 '21 at 01:44
  • And this is a potential roadblock https://stackoverflow.com/questions/54931327/azure-node-sdk-to-get-more-than-50-virtual-machines – Aravind Reddy Jun 18 '21 at 02:12