spring-bootazureazure-resource-managerazure-management

How to retrieve managament groups in hierarchy (managment groups /subscription / resources in each group) using java


I'm building an application and I need to retrieve all management groups in a hierarchical style like the subscription IDs and that resource informations .

I looked up in the SDK for java :(https://github.com/Azure/azure-sdk-for-java)

but can't find anything related with my topic

I went through tones of documentations but still didn't find any significant class that can help


Solution

  • Refer to MSDOC to access the management group list from azure by using azure REST Api call for the list management api.

    To access the above api we should have the following details:

    1. Client ID
    2. Client Secret
    3. Tenant ID

    With the help of above credentials, we can generate access token to access the api’s in azure.

    Below is the API to generate the access token.

    https://login.microsoftonline.com/<your-tenant-id>/oauth2/token

    enter image description here

    Use the generated token as header in the below api to access management groups:
    https://management.azure.com/providers/Microsoft.Management/managementGroups?api-version=2020-05-01

    enter image description here

    I have implemented the above scenario using java and spring boot by following the code.

    Output:

    In my case, I have only one management groups. So, I'm getting one management group as shown below. enter image description here