Azure: how to get Virtual machine power state?


I am currently trying to get all Virtual machines in a subscription, but I’d like to exclude the ones that are Stopped.

Here is what I tried:

data "azurerm_resources" "vm" {
  type = "Microsoft.Compute/virtualMachines"

This returns some values but not the power state.

So I tried:

data "azurerm_virtual_machine" "example" {
  name  = "myvm"
  resource_group_name = "My-RG"

This returns more values, but still no power state :frowning:

Does anyone know how to fetch the power state of a Virtual machine ?

Thanks !