How to get list of resource groups by tag name?

Tanul 1,246 Reputation points
2023-07-11T13:54:50.77+00:00

I need to list all resource groups in a subscription by tag name.. Any suggestion please. Tried these

REST API
"https://management.azure.com/subscriptions/fe3346a9-d41b-43f6-9561-c93c2f191b2d/resourcegroups?$filter=tagValue eq default&api-version=2021-04-01"

Terraform Az api provider

resource "azapi_resource" "symbolicname" {
  type = "Microsoft.Resources/resourceGroups@2021-04-01"
  parent_id="/subscriptions/<id>"
  tags = {
    portfolio = "default"    
  }  
  schema_validation_enabled = false
}
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
35,013 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Dillon Silzer 52,741 Reputation points
    2023-07-11T15:21:56.56+00:00

    Hello,

    You would want to use the following (Gets all the resource groups for a subscription by tag):

    GET https://management.azure.com/subscriptions/{subscriptionId}/resourcegroups?api-version=2021-04-01&$filter=tagname eq 'tagvalue'
    

    Cited from https://learn.microsoft.com/en-us/rest/api/resources/resource-groups/list User's image


    If this is helpful please accept answer.