powershellazureazure-cliazure-availability-set

Azure how to receive the assigned fault domain id of a virtual machine in an availability set using any CLI/API?


I'm trying to retrieving the Fault Domain ID of a VM inside an availability set. Those ID's are assigned "by random" to the virtual machines in question but it is important for me and the application to know what fault domain id the vm is assigned to. (By random b/c we generate the ~21 VMs at the same time using terraform)

On the web portal of azure, this information is retrievable if you look at the availability set.

What I have tried:

Azure CLI --expand instanceView

On the page View Fault and Update Domains of virtual machine in Azure through Python Script they gave me an example of a command: this gives an error on the --expand attribute

az vm show -g [ResourceGroup] -n [VM_NAME] --expand instanceView

az: error: unrecognized arguments: --expand instanceView usage: az [-h] [--verbose] [--debug] [--output {json,jsonc,table,tsv}] [--query JMESPATH] {vm} ...

Azure CLI without --expand instanceView

This doesn't give an error but also does not give me the attribute.

Powershell

I also tried it whit Powershell but no success.

Get-AzureRmVM -ResourceGroupName $rg.ResourceGroupName | convertTo-json

Get-AzureRmAvailabilitySet -ResourceGroupName $rg.ResourceGroupName | convertTo-json


Does anyone have any idea how to retrieve the Domain Fault ID?


Solution

  • It is possible by using the REST API:

    https://management.azure.com/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/virtualMachines/%s/instanceView?api-version=2017-03-30

    So, I just wrote a REST API Client to retrieve my information, I don't know why it doesn't work in the CLI client, (Maybe a bug ?)