0
votes

I'm attempting to gather a full JSON representation of my Azure resources in a given subscription, but can't figure out how I enumerate the available sub-resources for a given resource type.

For example, I can get the Microsoft.Web/sites/{name} resource, but nothing in that response tells me that Microsoft.Web/sites/{name}/config exists. Neither can I find any reference to the /config resource in the Provider object.

Azure Resource Explorer seems to be enumerating them dynamically with very little performance overhead, so I believe it's possible to do this. I just can't figure out how. Examples from NodeJS using the azure-arm-resource nom package:

// Returns a data structure, but nothing about subtypes.
let p = client.providers.get("Microsoft.Web");
// Contains the resource, but not the resources subtypes (e.g. config/appsettings
let r = client.resources.getById(resourceId, apiVersion);

I'm looking for something in the APIs that will give me an array of subtypes; in the case of Microsoft.Web/sites, that would be something like ["config", "containerlogs", "diagnostics"...] etc.

1
Does it need to work in a NodeJS project? - jarrad_obrien
Ideally. My project is in Node and Typescript at the moment. Having said that, if you can answer how to enumerate the sub resources via REST, .NET, or any other SDK then I should be able to figure it out in Node. - Rhysk
Would a PowerShell solution be useful? - jarrad_obrien
Yes, if it gets the properties in the question. - Rhysk

1 Answers

0
votes

This would be the call you are looking for:

https://management.azure.com/subscriptions/xxx/providers/Microsoft.Web?api-version=2019-05-10

It return something like this:

{
    "resourceTypes": [
        {
            "resourceType": "components",
            "locations": [ xxx ],
            "apiVersions": [ yyy ],
        },
        xxx,
        yyy
    ]
}

So you need to examine the output of your call more carefully. or just do a plain rest request and parse the output. but in all honesty, components() do not change all that much, you might as well hardcode the list.