question

NikunjBadjatya-8851 avatar image
0 Votes"
NikunjBadjatya-8851 asked JamesHamil-MSFT answered

Get list of subscriptions using clientSecretCredential method

Hello,

We want to find tags for all azure subscriptions in a azure tenant.

Let's say there are N subscriptions (subscription1, subscription2, ...) in an Azure Tenant T1.
Each of these subscriptions has some tags created at the subscription level.

Now in another tenant T2, an azure multitenant app (app1) is created. T2 is the home tenant for this app1 and has got clientid and clientsecret.
app1 is registered in T1 as a serviceprincipal.
app1 is assigned necessary permissions at each of the subscriptions in T1 to be able to get tags at resource level.

Now using java sdk ClientSecretCredential method, we are able to authenticate per subscription and retrieve the tags available at subscription level.
Sample code:

             ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder()
                     .clientId(CLIENT_ID)
                     .clientSecret(CLIENT_SECRET)
                     .tenantId(TENANT_ID_1)
                     .build();
             AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);            
    
             AzureResourceManager azure = AzureResourceManager
                     .authenticate(clientSecretCredential, profile)
                     .withSubscription(SUBSCRIPTION_ID_1);
    
             TagsResourceInner tagsResourceInner2 = azure.genericResources().manager().
                                                     serviceClient().getTagOperations().
                                                     getAtScope("/subscriptions/<SUBSCRIPTION_ID_1>/");
             System.out.println(tagsResourceInner2.properties().tags());


My question is, if there are N subscriptions in T1, and the subs list can change over time, how to programmatically using java sdk get list of subscriptions ? So that we can fetch tags for all.




azure-active-directoryazure-managed-applications
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @NikunjBadjatya-8851 , may I ask what your use case is for this? It can help me narrow down a solution. Also, have you seen this document? This utilizes PowerShell, but it might be easier to do it this way than with java. Please let me know and I can help you further.

Thank you,
James



0 Votes 0 ·

Hello @JamesHamil-MSFT Thanks for reaching out.

Our usecase is to find subs level tags for each sub in a tenant. For N tenants. (We hold business specific subscription data with us and we want to also add subs tags in it.)

We would like to stick to Java sdks (as our backend is in Java) unless sdk has some shortcomings.

using client secret credential method allows to execute apis on client (customer) azure account. This method works fine for our other usecases but not working as expected for gettings subs level tags.


0 Votes 0 ·

Any updates on this ? @JamesHamil-MSFT

0 Votes 0 ·
Show more comments

1 Answer

JamesHamil-MSFT avatar image
0 Votes"
JamesHamil-MSFT answered

Hi @ NikunjBadjatya-8851 , sorry for the delay in response. I was awaiting a response from the product team.

You can use: azure.subscriptions().list() as long as app1 has permission to all required subscriptions. subscription ID is Subscription.subscriptionId()

Please let me know if you have any questions and I can help you further.

If this answer helped you please mark it as "Verified" so other users can reference it.

Thank you,
James

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.